Skip to content

Commit 3550e26

Browse files
authored
Merge pull request #459 from GUMUNYEONG/main
[GUMUNYEONG] week 5 solution
2 parents 62207e0 + 06ae7fd commit 3550e26

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} prices
3+
* @return {number}
4+
*/
5+
var maxProfit = function (prices) {
6+
let max = 0;
7+
8+
for (let i = 0; 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+
18+
// TC : O(n^2);
19+
// SC : O(1);

0 commit comments

Comments
 (0)