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 742008b commit 9151908Copy full SHA for 9151908
best-time-to-buy-and-sell-stock/soobing.bak.ts
@@ -0,0 +1,14 @@
1
+function maxProfit(prices: number[]): number {
2
+ let minPrice = Infinity;
3
+ let maxProfit = 0;
4
+ for(let i=0; i<prices.length; i++) {
5
+ if(prices[i] < minPrice) {
6
+ minPrice = prices[i];
7
+ }
8
+
9
+ if(prices[i] - minPrice > maxProfit) {
10
+ maxProfit = prices[i] - minPrice;
11
12
13
+ return maxProfit;
14
+};
0 commit comments