From a0edb9f2d0e93cf8e72d76073257d5ea20c86051 Mon Sep 17 00:00:00 2001 From: Dahae Date: Sun, 16 Nov 2025 19:04:42 +0900 Subject: [PATCH 1/3] contains duplicate --- contains-duplicate/pastelto.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 contains-duplicate/pastelto.java diff --git a/contains-duplicate/pastelto.java b/contains-duplicate/pastelto.java new file mode 100644 index 000000000..015de15d1 --- /dev/null +++ b/contains-duplicate/pastelto.java @@ -0,0 +1,14 @@ +/* + Return true when array contains duplicated number + */ +class Solution { + public boolean containsDuplicate(int[] nums) { + HashSet set = new HashSet<>(); + + for (int num : nums) { + if (set.contains(num)) return true; + set.add(num); + } + return false; + } +} \ No newline at end of file From 98d4360f6b82d1ddde4ffb455a198e127bba181f Mon Sep 17 00:00:00 2001 From: Dahae Date: Sun, 16 Nov 2025 19:28:15 +0900 Subject: [PATCH 2/3] refactor - add newline --- contains-duplicate/pastelto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contains-duplicate/pastelto.java b/contains-duplicate/pastelto.java index 015de15d1..461824e26 100644 --- a/contains-duplicate/pastelto.java +++ b/contains-duplicate/pastelto.java @@ -11,4 +11,4 @@ public boolean containsDuplicate(int[] nums) { } return false; } -} \ No newline at end of file +} From ced3f8e4ef9969fbb7130daeda2c5efedfd2ab51 Mon Sep 17 00:00:00 2001 From: Dahae Date: Sun, 16 Nov 2025 19:28:36 +0900 Subject: [PATCH 3/3] two sum solution --- two-sum/pastelto.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 two-sum/pastelto.java diff --git a/two-sum/pastelto.java b/two-sum/pastelto.java new file mode 100644 index 000000000..eb0d05138 --- /dev/null +++ b/two-sum/pastelto.java @@ -0,0 +1,12 @@ +class Solution { + public int[] twoSum(int[] nums, int target) { + for (int i = 0; i < nums.length - 1; i++) { + for (int j = i+1; j < nums.length; j++) { + if (nums[i] + nums[j] == target) { + return new int[]{i, j}; + } + } + } + return new int[]{}; + } +}