diff --git a/3sum/mintheon.java b/3sum/mintheon.java new file mode 100644 index 000000000..37d39e3cc --- /dev/null +++ b/3sum/mintheon.java @@ -0,0 +1,35 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +class Solution { + public List> threeSum(int[] nums) { + Arrays.sort(nums); + + Set> answer = new HashSet<>(); + + for(int i = 0; i < nums.length - 2; i++) { + int left = i + 1; + int right = nums.length - 1; + + while(left < right) { + int sum = nums[i] + nums[left] + nums[right]; + + if(sum < 0) { + left++; + } else if(sum > 0) { + right--; + } else{ + answer.add(List.of(nums[i], nums[left], nums[right])); + + left++; + right--; + } + } + } + + return new ArrayList<>(answer); + } +} diff --git a/climbing-stairs/mintheon.java b/climbing-stairs/mintheon.java new file mode 100644 index 000000000..9ab63331c --- /dev/null +++ b/climbing-stairs/mintheon.java @@ -0,0 +1,17 @@ +class Solution { + public int climbStairs(int n) { + int[] stepCount = new int[n + 1]; + + if(n == 1) { + return 1; + } + + stepCount[1] = 1; + stepCount[2] = 2; + for(int i = 3; i <= n; i++) { + stepCount[i] = stepCount[i - 1] + stepCount[i - 2]; + } + + return stepCount[n]; + } +} diff --git a/valid-anagram/mintheon.java b/valid-anagram/mintheon.java new file mode 100644 index 000000000..0fa6917b2 --- /dev/null +++ b/valid-anagram/mintheon.java @@ -0,0 +1,13 @@ +import java.util.Arrays; + +class Solution { + public boolean isAnagram(String s, String t) { + char[] sChar = s.toCharArray(); + char[] tChar = t.toCharArray(); + + Arrays.sort(sChar); + Arrays.sort(tChar); + + return Arrays.equals(sChar, tChar); + } +}