Skip to content

Commit 431dad4

Browse files
refactor for format
1 parent 1ec9b75 commit 431dad4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+123
-56
lines changed

src/main/java/com/fishercoder/solutions/_125.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
public class _125 {
1414

1515
public boolean isPalindrome(String s) {
16-
int i = 0, j = s.length() - 1;
16+
int i = 0;
17+
int j = s.length() - 1;
1718
char[] chars = s.toCharArray();
1819
while (i < j) {
1920
while (i < j && !Character.isLetterOrDigit(chars[i])) {

src/main/java/com/fishercoder/solutions/_130.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class _130 {
3838

3939
public void solve(char[][] board) {
4040
if (board == null || board.length == 0 || board[0].length == 0) return;
41-
int m = board.length, n = board[0].length;
41+
int m = board.length;
42+
int n = board[0].length;
4243
Queue<int[]> queue = new LinkedList();
4344
//check first row and last row and mark all those '0' on these two rows to be '+' to let them be different from other 'O',
4445
//at the same time, we put them into the queue to get ready for a BFS to mark all those adjacent 'O' nodes to '+' as well

src/main/java/com/fishercoder/solutions/_142.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
public class _142 {
1212

1313
public ListNode detectCycle(ListNode head) {
14-
ListNode slow = head, fast = head;
14+
ListNode slow = head;
15+
ListNode fast = head;
1516
while (fast != null && fast.next != null) {
1617
slow = slow.next;
1718
fast = fast.next.next;

src/main/java/com/fishercoder/solutions/_143.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public void reorderList(ListNode head) {
2020
return;
2121
}
2222
/* first we use two pointers to separate this list into two parts */
23-
ListNode slowNode = head, fastNode = head;
23+
ListNode slowNode = head;
24+
ListNode fastNode = head;
2425
while (fastNode.next != null) {
2526
fastNode = fastNode.next;
2627
if (fastNode.next != null) {
@@ -31,12 +32,14 @@ public void reorderList(ListNode head) {
3132
slowNode = slowNode.next;
3233
}
3334
// two sublist heads
34-
ListNode head1 = head, head2 = slowNode.next;
35+
ListNode head1 = head;
36+
ListNode head2 = slowNode.next;
3537
// detach the two sublists;
3638
slowNode.next = null;
3739

3840
// reverse the second sublist
39-
ListNode cur = head2, post = cur.next;
41+
ListNode cur = head2;
42+
ListNode post = cur.next;
4043
cur.next = null;
4144
while (post != null) {
4245
ListNode temp = post.next;
@@ -47,7 +50,8 @@ public void reorderList(ListNode head) {
4750
head2 = cur;// the new head of the reversed sublist
4851

4952
// merge the two sublists as required
50-
ListNode p = head1, q = head2;
53+
ListNode p = head1;
54+
ListNode q = head2;
5155
while (q != null) {
5256
ListNode temp1 = p.next;
5357
ListNode temp2 = q.next;

src/main/java/com/fishercoder/solutions/_152.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
public class _152 {
1010

1111
public int maxProduct(int[] nums) {
12-
int pos = nums[0], neg = nums[0];
12+
int pos = nums[0];
13+
int neg = nums[0];
1314
int max = nums[0];
1415
for (int i = 1; i < nums.length; i++) {
1516
int temp = pos;

src/main/java/com/fishercoder/solutions/_157.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
*/
1919
public class _157 {
2020
public int read(char[] buf, int n) {
21-
int index = 0, next = 0;
21+
int index = 0;
22+
int next = 0;
2223
char[] buffer = new char[4];
2324
while (index < n && (next = read4(buffer)) != 0) {
2425
for (int i = 0; i < next && index < n; index++, i++) {

src/main/java/com/fishercoder/solutions/_16.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public int threeSumClosest(int[] nums, int target) {
2323
}
2424
int sum = nums[0] + nums[1] + nums[2];
2525
for (int i = 0; i < nums.length - 2; i++) {
26-
int left = i + 1, right = nums.length - 1;
26+
int left = i + 1;
27+
int right = nums.length - 1;
2728
while (left < right) {
2829
int thisSum = nums[i] + nums[left] + nums[right];
2930
if (Math.abs(target - thisSum) < Math.abs(target - sum)) {

src/main/java/com/fishercoder/solutions/_160.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public class _160 {
3232
public static class Solution1 {
3333

3434
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
35-
int lenA = findLen(headA), lenB = findLen(headB);
35+
int lenA = findLen(headA);
36+
int lenB = findLen(headB);
3637
/**align headA and headB to the same starting point and then move together until we find the intersection point*/
3738
while (lenA < lenB) {
3839
headB = headB.next;

src/main/java/com/fishercoder/solutions/_161.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ public static boolean isOneEditDistance(String s, String t) {
1111
char[] longer = (s.length() > t.length()) ? schar : tchar;
1212
char[] shorter = (longer == schar) ? tchar : schar;
1313

14-
int diffCnt = 0, i = 0, j = 0;
14+
int diffCnt = 0;
15+
int i = 0;
16+
int j = 0;
1517
for (; i < shorter.length && j < longer.length; ) {
1618
if (longer[j] != shorter[i]) {
1719
diffCnt++;

src/main/java/com/fishercoder/solutions/_162.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class _162 {
2222
public static int findPeakElement_Ologn(int[] nums) {
2323

2424
if (nums == null || nums.length == 0) return 0;
25-
int left = 0, right = nums.length - 1;
25+
int left = 0;
26+
int right = nums.length - 1;
2627
while (left + 1 < right) {
2728
int mid = left + (right - left) / 2;
2829
if (nums[mid] < nums[mid + 1]) {
@@ -48,7 +49,8 @@ public static void main(String... strings) {
4849
*/
4950
public static int findPeakElement(int[] nums) {
5051
if (nums == null || nums.length == 0) return 0;
51-
int n = nums.length, result = 0;
52+
int n = nums.length;
53+
int result = 0;
5254
for (int i = 0; i < n; i++) {
5355
if (i == 0 && n > 1 && nums[i] > nums[i + 1]) {
5456
result = i;

0 commit comments

Comments
 (0)