Skip to content

Commit 7bd523f

Browse files
authored
Merge pull request #10 from xchux/fix/foramt-and-solutions
Fix/foramt and solutions
2 parents 55fb19b + 2ee1903 commit 7bd523f

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

Diff for: solutions/125.Valid Palindrome/Solution.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ public boolean isPalindrome(String s) {
33
s = s.toLowerCase().replaceAll("[^a-z0-9]", "");
44
int i = 0, j = s.length() - 1;
55
while (i < j) {
6-
if (s.charAt(i++) != s.charAt(j--)) return false;
6+
if (s.charAt(i++) != s.charAt(j--))
7+
return false;
78
}
89
return true;
910
}

Diff for: solutions/128. Longest Consecutive Sequence/Solution.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.util.*;
2+
13
class Solution {
24
public int longestConsecutive(int[] nums) {
35
Set<Integer> numSet = new HashSet<>();

Diff for: solutions/15. 3Sum/Solution.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.util.*;
2+
13
class Solution {
24
public List<List<Integer>> threeSum(int[] nums) {
35
List<List<Integer>> res = new ArrayList<>();

Diff for: solutions/15. 3Sum/Solution.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ def threeSum(self, nums: list[int]) -> list[list[int]]:
44
n = len(nums)
55
returnList = []
66
for i, i_num in enumerate(nums):
7-
if i and i_num == nums[i-1]:
7+
if i and i_num == nums[i - 1]:
88
continue
9-
l = i + 1
10-
r = n - 1
11-
while l < r:
12-
sum = i_num + nums[l] + nums[r]
9+
left = i + 1
10+
right = n - 1
11+
while left < right:
12+
sum = i_num + nums[left] + nums[right]
1313
if sum == 0:
14-
returnList.append([i_num, nums[l], nums[r]])
15-
while l < r and nums[l] == nums[l+1]:
16-
l += 1
17-
while l < r and nums[r] == nums[r-1]:
18-
r -= 1
19-
l += 1
20-
r -= 1
14+
returnList.append([i_num, nums[left], nums[right]])
15+
while left < right and nums[left] == nums[left + 1]:
16+
left += 1
17+
while left < right and nums[right] == nums[right - 1]:
18+
right -= 1
19+
left += 1
20+
right -= 1
2121
elif sum < 0:
22-
l += 1
22+
left += 1
2323
else:
24-
r -= 1
24+
right -= 1
2525
return returnList

Diff for: solutions/167. Two Integer Sum II/Solution.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ public int[] twoSum(int[] numbers, int target) {
55
while (left < right) {
66
int sum = numbers[left] + numbers[right];
77
if (sum == target) {
8-
return new int[] {left + 1, right + 1};
8+
return new int[] { left + 1, right + 1 };
99
} else if (sum < target) {
1010
left++;
1111
} else {
1212
right--;
1313
}
1414
}
1515

16-
return result;
16+
return new int[] { -1, -1 };
1717
}
1818
}

Diff for: solutions/20. Valid Parentheses/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import java.util.Stack;
1+
import java.util.*;
22

33
class Solution {
44
public boolean isValid(String s) {

0 commit comments

Comments
 (0)