From 5768268d12f8f5aa6ed9d13cc80aa15ad427f90c Mon Sep 17 00:00:00 2001 From: JinuCheon Date: Sat, 27 Jun 2026 21:20:15 +0900 Subject: [PATCH 1/4] 217. Contains Duplicate --- contains-duplicate/JinuCheon.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 contains-duplicate/JinuCheon.java diff --git a/contains-duplicate/JinuCheon.java b/contains-duplicate/JinuCheon.java new file mode 100644 index 0000000000..a05c59a0b7 --- /dev/null +++ b/contains-duplicate/JinuCheon.java @@ -0,0 +1,28 @@ +import java.util.HashSet; +import java.util.Set; + +class Solution { + /** + * 79/79 cases passed (19 ms) + * Your runtime beats 32.04 % of java submissions + * Your memory usage beats 6.16 % of java submissions (108.1 MB) + * + * When I changed HashSet to LinkedHashSet, the runtime and memory usage increased a little bit. + * + * Improvement: + * if (!set.add(num)) return true; // when num is already in the set, return true. + * It looks like more simple. + */ + public boolean containsDuplicate(int[] nums) { + Set exist = new HashSet<>(); + + for (int num : nums) { + if (exist.contains(num)) { + return true; + } else { + exist.add(num); + } + } + return false; + } +} From 45f13c415b19638c5d1921d6585beaf88281ab56 Mon Sep 17 00:00:00 2001 From: JinuCheon Date: Sat, 27 Jun 2026 22:52:52 +0900 Subject: [PATCH 2/4] Two Sum --- two-sum/JinuCheon.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 two-sum/JinuCheon.java diff --git a/two-sum/JinuCheon.java b/two-sum/JinuCheon.java new file mode 100644 index 0000000000..a67acc1341 --- /dev/null +++ b/two-sum/JinuCheon.java @@ -0,0 +1,36 @@ +// Follow-up: Can you come up with an algorithm that is less than O(n2) time complexity? +// O(n2) +// class Solution1 { +// public int[] twoSum(int[] nums, int target) { +// int size = nums.length; +// for (int i=0; i map = new HashMap<>(); + + for (int i = 0; i < nums.length; i++) { + int pair = target - nums[i]; + + if (map.containsKey(pair)) { + return new int[]{i, map.get(pair)}; + } + + map.put(nums[i], i); + } + throw new IllegalArgumentException(); + } +} From b174a0f6422f74d60104b6074109e3b8e3b07e9c Mon Sep 17 00:00:00 2001 From: JinuCheon Date: Mon, 29 Jun 2026 22:50:46 +0900 Subject: [PATCH 3/4] valid anagram --- valid-anagram/JinuCheon.py | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 valid-anagram/JinuCheon.py diff --git a/valid-anagram/JinuCheon.py b/valid-anagram/JinuCheon.py new file mode 100644 index 0000000000..1966dd6b16 --- /dev/null +++ b/valid-anagram/JinuCheon.py @@ -0,0 +1,39 @@ +# my own solution +# O(n) +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + count1 = {} + for ch in s: + count1[ch] = count1.get(ch, 0) + 1 + + count2 = {} + for ch in t: + count2[ch] = count2.get(ch, 0) + 1 + + return count1 == count2 + +# gpt suggestion +### half space +#### O(n) +class Solution2: + def isAnagram(self, s: str, t: str) -> bool: + count = {} + for ch in s: + count[ch] = count.get(ch, 0) + 1 + for ch in t: + count[ch] = count.get(ch, 0) - 1 + return all(v == 0 for v in count.values()) + +### simple solution (What??) +#### O(n) +#### Counter works like my own solution internally. But I'm ganna forgot this, becuase I'm learning now. +from collections import Counter +class Solution3: + def isAnagram(self, s: str, t: str) -> bool: + return Counter(s) == Counter(t) + +### using sort +#### O(n log n) +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + return sorted(s) == sorted(t) \ No newline at end of file From b60683106d92334c4591861b4963710846568a3f Mon Sep 17 00:00:00 2001 From: JinuCheon Date: Wed, 1 Jul 2026 23:26:22 +0900 Subject: [PATCH 4/4] climbing stairs --- climbing-stairs/JinuCheon.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 climbing-stairs/JinuCheon.py diff --git a/climbing-stairs/JinuCheon.py b/climbing-stairs/JinuCheon.py new file mode 100644 index 0000000000..e8e6215e45 --- /dev/null +++ b/climbing-stairs/JinuCheon.py @@ -0,0 +1,32 @@ +# 재귀를 만드는 것이 잘 생각나지 않아서, 이렇게 저렇게 시도해보다 결국 LLM 도움. +# 그렇지만 제출 결과 Time Out. +# 2^N 복잡도임. max 45 의 경우 35,184,372,088,832. +class Solution: + def climbStairs(self, n: int) -> int: + # 1 -> 한칸만 가능 + # 2 -> (1,1) or (2) + if n <= 2: + return n; + + # 1칸 진행한 케이스 + 2칸 진행한 케이스 + return self.climbStairs(n-1) + self.climbStairs(n-2); + +# memonization 적용. 실무를 하고나서 이걸 보니, 캐싱이라고 부르고 싶다. +# 1~N 숫자 하나당 한번의 계산을 하게 되니, 시간복잡도는 O(1) 이다. +# 이게 왜 easy 난이도지? 잊어먹었다가 주말에 자력으로 풀어보자. +class Solution: + def climbStairs(self, n: int) -> int: + self.memo = {} + return self.dfs(n) + + def dfs(self, n: int) -> int: + if n <= 2: + return n + + # 이미 해당 수를 계산한 적이 있다면 early return. + if n in self.memo: + return self.memo[n] + + # 새로운 결과가 있으면 무조건 저장. + self.memo[n] = self.dfs(n - 1) + self.dfs(n - 2) + return self.memo[n] \ No newline at end of file