From 6f71f95be1ca889b8cb47b54e5e74656fda7117f Mon Sep 17 00:00:00 2001 From: JIHOON LEE Date: Tue, 29 Apr 2025 15:24:46 +0900 Subject: [PATCH 1/3] solving Week 5 --- best-time-to-buy-and-sell-stock/jiji-hoon96.ts | 0 encode-and-decode-strings/jiji-hoon96.ts | 0 group-anagrams/jiji-hoon96.ts | 0 implement-trie-prefix-tree/jiji-hoon96.ts | 0 word-break/jiji-hoon96.ts | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 best-time-to-buy-and-sell-stock/jiji-hoon96.ts create mode 100644 encode-and-decode-strings/jiji-hoon96.ts create mode 100644 group-anagrams/jiji-hoon96.ts create mode 100644 implement-trie-prefix-tree/jiji-hoon96.ts create mode 100644 word-break/jiji-hoon96.ts diff --git a/best-time-to-buy-and-sell-stock/jiji-hoon96.ts b/best-time-to-buy-and-sell-stock/jiji-hoon96.ts new file mode 100644 index 000000000..e69de29bb diff --git a/encode-and-decode-strings/jiji-hoon96.ts b/encode-and-decode-strings/jiji-hoon96.ts new file mode 100644 index 000000000..e69de29bb diff --git a/group-anagrams/jiji-hoon96.ts b/group-anagrams/jiji-hoon96.ts new file mode 100644 index 000000000..e69de29bb diff --git a/implement-trie-prefix-tree/jiji-hoon96.ts b/implement-trie-prefix-tree/jiji-hoon96.ts new file mode 100644 index 000000000..e69de29bb diff --git a/word-break/jiji-hoon96.ts b/word-break/jiji-hoon96.ts new file mode 100644 index 000000000..e69de29bb From 30c323fa2a6b6eb8e767a1a83cba1e14db26976e Mon Sep 17 00:00:00 2001 From: JIHOON LEE Date: Sat, 3 May 2025 18:44:57 +0900 Subject: [PATCH 2/3] solution : Best Time to Buy And Sell Stock --- .../jiji-hoon96.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/best-time-to-buy-and-sell-stock/jiji-hoon96.ts b/best-time-to-buy-and-sell-stock/jiji-hoon96.ts index e69de29bb..71aebd6fb 100644 --- a/best-time-to-buy-and-sell-stock/jiji-hoon96.ts +++ b/best-time-to-buy-and-sell-stock/jiji-hoon96.ts @@ -0,0 +1,23 @@ +function maxProfit(prices: number[]): number { + if (prices.length <= 1) return 0; + + let minPrice = prices[0]; + let maxProfit = 0; + + for (let i = 1; i < prices.length; i++) { + // 현재 가격이 최소가보다 낮으면 최소가 업데이트 + if (prices[i] < minPrice) { + minPrice = prices[i]; + } + // 현재 가격으로 팔았을 때의 이익 계산 + else { + const currentProfit = prices[i] - minPrice; + // 최대 이익 업데이트 + if (currentProfit > maxProfit) { + maxProfit = currentProfit; + } + } + } + + return maxProfit; +} \ No newline at end of file From 30cbd7ce11152f3c234e1269f64c08cb1920f31d Mon Sep 17 00:00:00 2001 From: JIHOON LEE Date: Sat, 3 May 2025 18:45:03 +0900 Subject: [PATCH 3/3] solution : Best Time to Buy And Sell Stock --- best-time-to-buy-and-sell-stock/jiji-hoon96.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best-time-to-buy-and-sell-stock/jiji-hoon96.ts b/best-time-to-buy-and-sell-stock/jiji-hoon96.ts index 71aebd6fb..84c6244d5 100644 --- a/best-time-to-buy-and-sell-stock/jiji-hoon96.ts +++ b/best-time-to-buy-and-sell-stock/jiji-hoon96.ts @@ -20,4 +20,4 @@ function maxProfit(prices: number[]): number { } return maxProfit; -} \ No newline at end of file +}