some solutions for projects on odin project
This commit is contained in:
26
stock_picker.rb
Normal file
26
stock_picker.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
### STOCK PICKER
|
||||
def stock_picker(stock_prices)
|
||||
left = 0
|
||||
right = 1
|
||||
highest = 0
|
||||
solution = [nil, nil]
|
||||
|
||||
until left == stock_prices.length - 1
|
||||
until right == stock_prices.length - 1
|
||||
right += 1
|
||||
temp = stock_prices[right] - stock_prices[left]
|
||||
if temp > highest
|
||||
highest = temp
|
||||
solution[0] = left
|
||||
solution[1] = right
|
||||
end
|
||||
end
|
||||
|
||||
left += 1
|
||||
right = left + 1 unless left + 1 == stock_prices.length
|
||||
end
|
||||
|
||||
solution
|
||||
end
|
||||
|
||||
print stock_picker([17,3,6,9,15,8,6,1,10])
|
||||
Reference in New Issue
Block a user