Skip to content

Commit 9a95106

Browse files
enable MultipleVariableDeclarations check!
1 parent f893b97 commit 9a95106

Some content is hidden

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

69 files changed

+259
-115
lines changed

fishercoder_checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<property name="allowNoEmptyLineBetweenFields" value="true"/>
116116
module>
117117

118-
<!--<module name="MultipleVariableDeclarations"/>-->
118+
<module name="MultipleVariableDeclarations"/>
119119

120120
<module name="SeparatorWrap">
121121
<property name="tokens" value="DOT"/>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public int maxProfit(int k, int[] prices) {
3030

3131

3232
private int quickSolve(int[] prices) {
33-
int len = prices.length, profit = 0;
33+
int len = prices.length;
34+
int profit = 0;
3435
for (int i = 1; i < len; i++) {
3536
// as long as there is a price gap, we gain a profit.
3637
if (prices[i] > prices[i - 1]) profit += prices[i] - prices[i - 1];

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public ListNode removeNthFromEnd_one_pass(ListNode head, int n) {
5656
//then, when fast reaches null, slow reaches the point where the node should be deleted.
5757
ListNode dummy = new ListNode(-1);
5858
dummy.next = head;
59-
ListNode slow = head, fast = head;
59+
ListNode slow = head;
60+
ListNode fast = head;
6061
int tempN = n;
6162
while (tempN-- > 0) {
6263
fast = fast.next;
@@ -87,7 +88,8 @@ public ListNode removeNthFromEnd_one_pass(ListNode head, int n) {
8788
public ListNode removeNthFromEnd_one_pass_more_concise_version(ListNode head, int n) {
8889
ListNode dummy = new ListNode(-1);
8990
dummy.next = head;
90-
ListNode slow = dummy, fast = dummy;
91+
ListNode slow = dummy;
92+
ListNode fast = dummy;
9193
while (fast.next != null) {
9294
if (n <= 0) slow = slow.next;
9395
fast = fast.next;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public static class DFSSolution {
3131
public int numIslands(char[][] grid) {
3232
if (grid == null || grid.length == 0) return 0;
3333
int count = 0;
34-
int m = grid.length, n = grid[0].length;
34+
int m = grid.length;
35+
int n = grid[0].length;
3536
for (int i = 0; i < m; i++) {
3637
for (int j = 0; j < n; j++) {
3738
if (grid[i][j] == '1') {
@@ -95,7 +96,8 @@ public int numIslands(char[][] grid) {
9596
if (grid == null || grid.length == 0 || grid[0].length == 0) return 0;
9697
int[] dirs = new int[]{0, 1, 0, -1, 0};
9798
UnionFind uf = new UnionFind(grid);
98-
int m = grid.length, n = grid[0].length;
99+
int m = grid.length;
100+
int n = grid[0].length;
99101
for (int i = 0; i < m; i++) {
100102
for (int j = 0; j < n; j++) {
101103
if (grid[i][j] == '1') {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public class _203 {
2626
public ListNode removeElements(ListNode head, int val) {
2727
ListNode dummy = new ListNode(-1);
2828
dummy.next = head;
29-
ListNode curr = head, prev = dummy;
29+
ListNode curr = head;
30+
ListNode prev = dummy;
3031
while (curr != null) {
3132
if (curr.val == val) {
3233
prev.next = curr.next;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public class _209 {
1515

1616
public int minSubArrayLen(int s, int[] nums) {
1717
if (nums == null || nums.length == 0) return 0;
18-
int i = 0, j = 0, min = Integer.MAX_VALUE, sum = 0;
18+
int i = 0;
19+
int j = 0;
20+
int min = Integer.MAX_VALUE;
21+
int sum = 0;
1922
while (j < nums.length) {
2023
sum += nums[j++];
2124

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class _221 {
1818
/**The idea is pretty straightforward: use a 2d dp table to store the intermediate results*/
1919
public static int maximalSquare(char[][] matrix) {
2020
if (matrix == null || matrix.length == 0) return 0;
21-
int m = matrix.length, n = matrix[0].length;
21+
int m = matrix.length;
22+
int n = matrix[0].length;
2223
int max = Integer.MIN_VALUE;
2324
int[][] dp = new int[m][n];
2425
for (int i = 0; i < m; i++) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public class _233 {
1616
public int countDigitOne(int n) {
1717
int count = 0;
1818
for (long k = 1; k <= n; k *= 10) {
19-
long r = n / k, m = n % k;
19+
long r = n / k;
20+
long m = n % k;
2021
// sum up the count of ones on every place k
2122
count += (r + 8) / 10 * k + (r % 10 == 1 ? m + 1 : 0);
2223
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public static class Solution1 {
2121
public boolean isPalindrome(ListNode head) {
2222
if (head == null) return true;
2323

24-
ListNode slow = head, fast = head;
24+
ListNode slow = head;
25+
ListNode fast = head;
2526
while (fast.next != null && fast.next.next != null) {
2627
fast = fast.next.next;
2728
slow = slow.next;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public class _243 {
1414

1515
public int shortestDistance(String[] words, String word1, String word2) {
1616

17-
int p = -1, q = -1, min = Integer.MAX_VALUE;
17+
int p = -1;
18+
int q = -1;
19+
int min = Integer.MAX_VALUE;
1820
for (int i = 0; i < words.length; i++) {
1921
if (words[i].equals(word1)) p = i;
2022
if (words[i].equals(word2)) q = i;

0 commit comments

Comments
 (0)