Skip to content

Commit ab5f639

Browse files
committed
solve problem
1 parent 8a9ba39 commit ab5f639

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
func maxProfit(_ prices: [Int]) -> Int {
3+
var lowPrice: Int = prices[0]
4+
var maxProfit: Int = 0
5+
for i in 0..<prices.endIndex {
6+
lowPrice = min(lowPrice, prices[i])
7+
maxProfit = max(maxProfit, prices[i] - lowPrice)
8+
}
9+
return maxProfit
10+
}
11+
}
12+

0 commit comments

Comments
 (0)