We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8a9ba39 commit ab5f639Copy full SHA for ab5f639
best-time-to-buy-and-sell-stock/delight010.swift
@@ -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