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 9ced22c commit 6aadb4bCopy full SHA for 6aadb4b
1 file changed
best-time-to-buy-and-sell-stock/soobing3.ts
@@ -0,0 +1,15 @@
1
+function maxProfit(prices: number[]): number {
2
+ let left = 0;
3
+ let right = 1;
4
+ let max = 0;
5
+
6
+ while(left < right && right < prices.length) {
7
+ if(prices[right] - prices[left] > 0) {
8
+ max = Math.max(max, prices[right] - prices[left])
9
+ } else {
10
+ left = right;
11
+ }
12
+ right++;
13
14
+ return max;
15
+};
0 commit comments