Skip to content

Commit

Permalink
Merge pull request #459 from GUMUNYEONG/main
Browse files Browse the repository at this point in the history
[GUMUNYEONG] week 5 solution
  • Loading branch information
GUMUNYEONG authored Sep 15, 2024
2 parents 62207e0 + 06ae7fd commit 3550e26
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions best-time-to-buy-and-sell-stock/GUMUNYEONG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function (prices) {
let max = 0;

for (let i = 0; i <= prices.length; i++) {
for (let j = i + 1; j <= prices.length; j++) {
const profit = prices[j] - prices[i];
max = profit > max ? profit : max;
}
}

return max;
};

// TC : O(n^2);
// SC : O(1);

0 comments on commit 3550e26

Please sign in to comment.