Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 1; 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

알고리즘 성능이 너무 떨어져서 LeetCode에 답안을 제출하면 시간 제한 초과에 걸릴 것 같네요. Brute-force한 방법으로 풀어보셨으니 나중에 시간 되실 때 좀 더 효율적인 알고리즘도 고민해보시면 좋을 것 같습니다.

// SC : O(1);