Skip to content

Commit 348c154

Browse files
author
mykoo
committed
best-time-to-buy-and-sell-stock
1 parent 0e98b10 commit 348c154

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[]} prices
3+
* @return {number}
4+
*/
5+
var maxProfit = function (prices) {
6+
let max = 0;
7+
8+
for (let i = 1; i <= prices.length; i++) {
9+
for (let j = i + 1; j <= prices.length; j++) {
10+
const profit = prices[j] - prices[i];
11+
max = profit > max ? profit : max;
12+
}
13+
}
14+
15+
return max;
16+
};
17+

0 commit comments

Comments
 (0)