Skip to content

Commit b4122dd

Browse files
authored
Merge pull request #1394 from jiji-hoon96/main
[jiji-hoon96] WEEK 05 solutions
2 parents 3ea621b + 30cbd7c commit b4122dd

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function maxProfit(prices: number[]): number {
2+
if (prices.length <= 1) return 0;
3+
4+
let minPrice = prices[0];
5+
let maxProfit = 0;
6+
7+
for (let i = 1; i < prices.length; i++) {
8+
// ํ˜„์žฌ ๊ฐ€๊ฒฉ์ด ์ตœ์†Œ๊ฐ€๋ณด๋‹ค ๋‚ฎ์œผ๋ฉด ์ตœ์†Œ๊ฐ€ ์—…๋ฐ์ดํŠธ
9+
if (prices[i] < minPrice) {
10+
minPrice = prices[i];
11+
}
12+
// ํ˜„์žฌ ๊ฐ€๊ฒฉ์œผ๋กœ ํŒ”์•˜์„ ๋•Œ์˜ ์ด์ต ๊ณ„์‚ฐ
13+
else {
14+
const currentProfit = prices[i] - minPrice;
15+
// ์ตœ๋Œ€ ์ด์ต ์—…๋ฐ์ดํŠธ
16+
if (currentProfit > maxProfit) {
17+
maxProfit = currentProfit;
18+
}
19+
}
20+
}
21+
22+
return maxProfit;
23+
}

โ€Žencode-and-decode-strings/jiji-hoon96.ts

Whitespace-only changes.

โ€Žgroup-anagrams/jiji-hoon96.ts

Whitespace-only changes.

โ€Žimplement-trie-prefix-tree/jiji-hoon96.ts

Whitespace-only changes.

โ€Žword-break/jiji-hoon96.ts

Whitespace-only changes.

0 commit comments

Comments
ย (0)