function maxTheStock(prices) {
let maxProfit = 0, minPrice = Infinity;
for (let price of prices) {
minPrice = Math.min(minPrice, price);
maxProfit = Math.max(price - minPrice, maxProfit);
}
return maxProfit;
}
function maxTheStock(prices) {
let maxProfit = 0, minPrice = Infinity;
for (let price of prices) {
minPrice = Math.min(minPrice, price);
maxProfit = Math.max(price - minPrice, maxProfit);
}
return maxProfit;
}
I had written a Rust implementation similar to this a year ago, so this one fell into place nicely!
I had written a Rust implementation similar to this a year ago, so this one fell into place nicely!
So schwer ist der Denkprozess beim Lieferkettengesetz doch nicht?
Du willst fair behandelt werden? Ja denkst du andere nicht? 🙄
Ressourcenverschwendung zwecks MaxProfit ist nicht cool 🙄
So schwer ist der Denkprozess beim Lieferkettengesetz doch nicht?
Du willst fair behandelt werden? Ja denkst du andere nicht? 🙄
Ressourcenverschwendung zwecks MaxProfit ist nicht cool 🙄
var currentMin = Int.MAX_VALUE
var maxProfit = 0
for (price in prices) {
currentMin = minOf(currentMin, price)
maxProfit = maxOf(maxProfit, price - currentMin)
}
return maxProfit
}
var currentMin = Int.MAX_VALUE
var maxProfit = 0
for (price in prices) {
currentMin = minOf(currentMin, price)
maxProfit = maxOf(maxProfit, price - currentMin)
}
return maxProfit
}
right++
}
left = right
}
return maxProfit
}
It has been a while since I’ve leetcoded and I’ve never written a function on my phone but I think that is close enough to working.
right++
}
left = right
}
return maxProfit
}
It has been a while since I’ve leetcoded and I’ve never written a function on my phone but I think that is close enough to working.
Receive load planning tailored for the nuances of inner-city deliveries.
smartroutelogistics.com
#UrbanDispatch #CityFreight #BoxTruckRoutes #DispatchExperts #MaxProfit
Receive load planning tailored for the nuances of inner-city deliveries.
smartroutelogistics.com
#UrbanDispatch #CityFreight #BoxTruckRoutes #DispatchExperts #MaxProfit
let maxProfit = 0
let left = 0
let right = 0
while (left < values.length) {
if (values[left] >= values[left + 1]) {
left++
}
right = left +1
while (right < values.length && values[right] > values[left]) {
let maxProfit = 0
let left = 0
let right = 0
while (left < values.length) {
if (values[left] >= values[left + 1]) {
left++
}
right = left +1
while (right < values.length && values[right] > values[left]) {
Сначала пишу аналог решения на Uiua:
fun maxProfit(prices: IntArray): Int {
val runningMin = prices.runningReduce(::minOf)
val bestPerDay = prices.zip(runningMin, Int::minus)
return bestPerDay.max()
}
Сначала пишу аналог решения на Uiua:
fun maxProfit(prices: IntArray): Int {
val runningMin = prices.runningReduce(::minOf)
val bestPerDay = prices.zip(runningMin, Int::minus)
return bestPerDay.max()
}