From 8ca17f7e20c722ebe5a910dbd11e32bc1c35356c Mon Sep 17 00:00:00 2001 From: toychip Date: Sat, 5 Apr 2025 16:40:14 +0900 Subject: [PATCH 1/5] contains-duplicate solution --- contains-duplicate/toychip.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 contains-duplicate/toychip.java diff --git a/contains-duplicate/toychip.java b/contains-duplicate/toychip.java new file mode 100644 index 000000000..79f0e6a5b --- /dev/null +++ b/contains-duplicate/toychip.java @@ -0,0 +1,16 @@ +import java.util.HashSet; +import java.util.Set; + +class Solution { + public boolean containsDuplicate(int[] nums) { + Set answer = new HashSet<>(); + for (int num : nums) { + if (!answer.contains(num)) { + answer.add(num); + } else { + return true; + } + } + return false; + } +} \ No newline at end of file From 536fa3c631930acad202f4c135d5fc04e19c460a Mon Sep 17 00:00:00 2001 From: toychip Date: Sat, 5 Apr 2025 16:41:28 +0900 Subject: [PATCH 2/5] two-sum solution --- two-sum/toychip.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 two-sum/toychip.java diff --git a/two-sum/toychip.java b/two-sum/toychip.java new file mode 100644 index 000000000..c9b408e2e --- /dev/null +++ b/two-sum/toychip.java @@ -0,0 +1,12 @@ +class Solution { + public int[] twoSum(int[] nums, int target) { + for (int i = 0; i < nums.length; i++) { + for (int j = i + 1; j < nums.length; j++) { + if (nums[i] + nums[j] == target) { + return new int[]{i, j}; + } + } + } + return null; + } +} \ No newline at end of file From b5e7e5728bd5da48dd1a4b8b159adae30933d0af Mon Sep 17 00:00:00 2001 From: junhyung Date: Tue, 8 Apr 2025 14:24:10 +0900 Subject: [PATCH 3/5] =?UTF-8?q?lint=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contains-duplicate/toychip.java | 2 +- two-sum/toychip.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contains-duplicate/toychip.java b/contains-duplicate/toychip.java index 79f0e6a5b..d0789dc32 100644 --- a/contains-duplicate/toychip.java +++ b/contains-duplicate/toychip.java @@ -13,4 +13,4 @@ public boolean containsDuplicate(int[] nums) { } return false; } -} \ No newline at end of file +} diff --git a/two-sum/toychip.java b/two-sum/toychip.java index c9b408e2e..91f0dc681 100644 --- a/two-sum/toychip.java +++ b/two-sum/toychip.java @@ -9,4 +9,4 @@ public int[] twoSum(int[] nums, int target) { } return null; } -} \ No newline at end of file +} From 2c55997b7f823b8a7cdba2fead2a9a82c0ca247b Mon Sep 17 00:00:00 2001 From: toychip Date: Tue, 8 Apr 2025 18:28:07 +0900 Subject: [PATCH 4/5] valid anagram solution --- valid-anagram/toychip.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 valid-anagram/toychip.java diff --git a/valid-anagram/toychip.java b/valid-anagram/toychip.java new file mode 100644 index 000000000..7c3bccfeb --- /dev/null +++ b/valid-anagram/toychip.java @@ -0,0 +1,20 @@ +class Solution { + public boolean isAnagram(String s, String t) { + if (s.length() != t.length()) { + return false; + } + + char[] sArray = s.toCharArray(); + Arrays.sort(sArray); + + char[] tArray = t.toCharArray(); + Arrays.sort(tArray); + + for (int i = 0; i < sArray.length; i++) { + if (sArray[i] != tArray[i]) { + return false; + } + } + return true; + } +} From ab1b00b45936e9103da44b96d36691302f977bf0 Mon Sep 17 00:00:00 2001 From: toychip Date: Tue, 8 Apr 2025 19:34:35 +0900 Subject: [PATCH 5/5] climbin-stars solution --- climbing-stairs/toychip.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 climbing-stairs/toychip.java diff --git a/climbing-stairs/toychip.java b/climbing-stairs/toychip.java new file mode 100644 index 000000000..ebdb3d282 --- /dev/null +++ b/climbing-stairs/toychip.java @@ -0,0 +1,23 @@ +class Solution { + public int climbStairs(int n) { + int[] memo = new int[n + 1]; + return recur(n, memo); + } + + int recur(int n, int[] memo) { + if (n < 0) { + return 0; + } + + if (n == 0) { + return 1; + } + + if (memo[n] > 0) { + return memo[n]; + } + + memo[n] = recur(n - 1, memo) + recur(n - 2, memo); + return memo[n]; + } +}