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 3bfd185 commit 2b9849eCopy full SHA for 2b9849e
best-time-to-buy-and-sell-stock/hozzijeong.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * @param {number[]} prices
3
+ * @return {number}
4
+ */
5
+var maxProfit = function(prices) {
6
+ let maxGap = 0;
7
+
8
+ for(let i =0; i < prices.length; i++){
9
+ const price = prices[i];
10
+ const restList = prices.slice(i);
11
12
+ const max = Math.max(...restList);
13
14
+ maxGap = Math.max(max-price, maxGap)
15
+ }
16
17
+ return maxGap
18
+};
19
0 commit comments