diff --git a/solutions/125.Valid Palindrome/Solution.java b/solutions/125.Valid Palindrome/Solution.java index 77349e7..db04b6f 100644 --- a/solutions/125.Valid Palindrome/Solution.java +++ b/solutions/125.Valid Palindrome/Solution.java @@ -3,7 +3,8 @@ public boolean isPalindrome(String s) { s = s.toLowerCase().replaceAll("[^a-z0-9]", ""); int i = 0, j = s.length() - 1; while (i < j) { - if (s.charAt(i++) != s.charAt(j--)) return false; + if (s.charAt(i++) != s.charAt(j--)) + return false; } return true; } diff --git a/solutions/128. Longest Consecutive Sequence/Solution.java b/solutions/128. Longest Consecutive Sequence/Solution.java index 84dddc0..453742c 100644 --- a/solutions/128. Longest Consecutive Sequence/Solution.java +++ b/solutions/128. Longest Consecutive Sequence/Solution.java @@ -1,3 +1,5 @@ +import java.util.*; + class Solution { public int longestConsecutive(int[] nums) { Set numSet = new HashSet<>(); diff --git a/solutions/15. 3Sum/Solution.java b/solutions/15. 3Sum/Solution.java index 30cd09b..bafb16a 100644 --- a/solutions/15. 3Sum/Solution.java +++ b/solutions/15. 3Sum/Solution.java @@ -1,3 +1,5 @@ +import java.util.*; + class Solution { public List> threeSum(int[] nums) { List> res = new ArrayList<>(); diff --git a/solutions/15. 3Sum/Solution.py b/solutions/15. 3Sum/Solution.py index 3c38e24..e64633d 100644 --- a/solutions/15. 3Sum/Solution.py +++ b/solutions/15. 3Sum/Solution.py @@ -4,22 +4,22 @@ def threeSum(self, nums: list[int]) -> list[list[int]]: n = len(nums) returnList = [] for i, i_num in enumerate(nums): - if i and i_num == nums[i-1]: + if i and i_num == nums[i - 1]: continue - l = i + 1 - r = n - 1 - while l < r: - sum = i_num + nums[l] + nums[r] + left = i + 1 + right = n - 1 + while left < right: + sum = i_num + nums[left] + nums[right] if sum == 0: - returnList.append([i_num, nums[l], nums[r]]) - while l < r and nums[l] == nums[l+1]: - l += 1 - while l < r and nums[r] == nums[r-1]: - r -= 1 - l += 1 - r -= 1 + returnList.append([i_num, nums[left], nums[right]]) + while left < right and nums[left] == nums[left + 1]: + left += 1 + while left < right and nums[right] == nums[right - 1]: + right -= 1 + left += 1 + right -= 1 elif sum < 0: - l += 1 + left += 1 else: - r -= 1 + right -= 1 return returnList diff --git a/solutions/167. Two Integer Sum II/Solution.java b/solutions/167. Two Integer Sum II/Solution.java index d350c61..95c19db 100644 --- a/solutions/167. Two Integer Sum II/Solution.java +++ b/solutions/167. Two Integer Sum II/Solution.java @@ -5,7 +5,7 @@ public int[] twoSum(int[] numbers, int target) { while (left < right) { int sum = numbers[left] + numbers[right]; if (sum == target) { - return new int[] {left + 1, right + 1}; + return new int[] { left + 1, right + 1 }; } else if (sum < target) { left++; } else { @@ -13,6 +13,6 @@ public int[] twoSum(int[] numbers, int target) { } } - return result; + return new int[] { -1, -1 }; } } diff --git a/solutions/20. Valid Parentheses/Solution.java b/solutions/20. Valid Parentheses/Solution.java index 06b6439..7e6359d 100644 --- a/solutions/20. Valid Parentheses/Solution.java +++ b/solutions/20. Valid Parentheses/Solution.java @@ -1,4 +1,4 @@ -import java.util.Stack; +import java.util.*; class Solution { public boolean isValid(String s) {