Skip to content

Commit 77452bc

Browse files
enable MemberName check
1 parent 1590ef5 commit 77452bc

14 files changed

+52
-52
lines changed

fishercoder_checkstyle.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@
112112
<!--<message key="name.invalidPattern"-->
113113
<!--value="Type name ''{0}'' must match pattern ''{1}''."/>-->
114114
<!--</module>-->
115-
<!--<module name="MemberName">-->
116-
<!--<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>-->
117-
<!--<message key="name.invalidPattern"-->
118-
<!--value="Member name ''{0}'' must match pattern ''{1}''."/>-->
119-
<!--</module>-->
115+
<module name="MemberName">
116+
<property name="format" value="^[a-z]*[a-z0-9][a-zA-Z0-9]*$"/>
117+
<message key="name.invalidPattern"
118+
value="Member name ''{0}'' must match pattern ''{1}''."/>
119+
</module>
120120
<module name="ParameterName">
121121
<property name="format" value="^[a-zA-Z][a-zA-Z0-9]*$"/>
122122
<message key="name.invalidPattern"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class _12 {
88
//looked at this post: https://discuss.leetcode.com/topic/12384/simple-solution
99
public String intToRoman(int num) {
10-
String M[] = new String[]{"", "M", "MM", "MMM"};
10+
String M[] = new String[]{"", "m", "MM", "MMM"};
1111
String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
1212
String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
1313
String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/**174. Dungeon Game
66
7-
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess.
7+
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of m x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess.
88
99
The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.
1010

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
On the other hand, we define that string s1 can be obtained from string s2 if we can remove some characters from s2 such that it becomes s1.
99
For example, “abc” can be obtained from “abdbec” based on our definition, but it can not be obtained from “acbbe”.
1010
You are given two non-empty strings s1 and s2 (each at most 100 characters long) and two integers 0 ≤ n1 ≤ 106 and 1 ≤ n2 ≤ 106.
11-
Now consider the strings S1 and S2, where S1=[s1,n1] and S2=[s2,n2]. Find the maximum integer M such that [S2,M] can be obtained from S1.
11+
Now consider the strings S1 and S2, where S1=[s1,n1] and S2=[s2,n2]. Find the maximum integer m such that [S2,m] can be obtained from S1.
1212
1313
Example:
1414

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.fishercoder.solutions;
22

33
/**
4-
* Now you are given a string S, which represents a software license key which we would like to format. The string S is composed of alphanumerical characters and dashes. The dashes split the alphanumerical characters within the string into groups. (i.e. if there are M dashes, the string is split into M+1 groups). The dashes in the given string are possibly misplaced.
4+
* Now you are given a string S, which represents a software license key which we would like to format. The string S is composed of alphanumerical characters and dashes. The dashes split the alphanumerical characters within the string into groups. (i.e. if there are m dashes, the string is split into m+1 groups). The dashes in the given string are possibly misplaced.
55
66
We want each group of characters to be of length K (except for possibly the first group, which could be shorter, but still must contain at least one character). To satisfy this requirement, we will reinsert dashes. Additionally, all the lower case letters in the string must be converted to upper case.
77

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ public class _488 {
4141
/**credit: https://discuss.leetcode.com/topic/79820/short-java-solution-beats-98
4242
* Two layer of recursion, pretty cool!*/
4343

44-
int MAXCOUNT = 6; // the max balls you need will not exceed 6 since "The number of balls in your hand won't exceed 5"
44+
int maxcount = 6; // the max balls you need will not exceed 6 since "The number of balls in your hand won't exceed 5"
4545

4646
public int findMinStep(String board, String hand) {
4747
int[] handCount = new int[26];
4848
for (int i = 0; i < hand.length(); ++i) {
4949
++handCount[hand.charAt(i) - 'A'];
5050
}
5151
int result = dfs(board + "#", handCount); // append a "#" to avoid special process while j==board.length, make the code shorter.
52-
return result == MAXCOUNT ? -1 : result;
52+
return result == maxcount ? -1 : result;
5353
}
5454
private int dfs(String s, int[] handCount) {
5555
s = removeConsecutive(s);
5656
if (s.equals("#")) return 0;
57-
int result = MAXCOUNT;
57+
int result = maxcount;
5858
int need = 0;
5959
for (int i = 0, j = 0 ; j < s.length(); ++j) {
6060
if (s.charAt(j) == s.charAt(i)) continue;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* 498. Diagonal Traverse
55
*
6-
* Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order
6+
* Given a matrix of m x N elements (m rows, N columns), return all elements of the matrix in diagonal order
77
* as shown in the below image.
88
99
Example:

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
/**
77
* Let's play the minesweeper game (Wikipedia, online game)!
88
9-
You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine, 'E' represents an unrevealed empty square, 'B' represents a revealed blank square that has no adjacent (above, below, left, right, and all 4 diagonals) mines, digit ('1' to '8') represents how many mines are adjacent to this revealed square, and finally 'X' represents a revealed mine.
9+
You are given a 2D char matrix representing the game board. 'm' represents an unrevealed mine, 'E' represents an unrevealed empty square, 'B' represents a revealed blank square that has no adjacent (above, below, left, right, and all 4 diagonals) mines, digit ('1' to '8') represents how many mines are adjacent to this revealed square, and finally 'X' represents a revealed mine.
1010
11-
Now given the next click position (row and column indices) among all the unrevealed squares ('M' or 'E'), return the board after revealing this position according to the following rules:
11+
Now given the next click position (row and column indices) among all the unrevealed squares ('m' or 'E'), return the board after revealing this position according to the following rules:
1212
13-
If a mine ('M') is revealed, then the game is over - change it to 'X'.
13+
If a mine ('m') is revealed, then the game is over - change it to 'X'.
1414
If an empty square ('E') with no adjacent mines is revealed, then change it to revealed blank ('B') and all of its adjacent unrevealed squares should be revealed recursively.
1515
If an empty square ('E') with at least one adjacent mine is revealed, then change it to a digit ('1' to '8') representing the number of adjacent mines.
1616
Return the board when no more squares will be revealed.
1717
Example 1:
1818
Input:
1919
2020
[['E', 'E', 'E', 'E', 'E'],
21-
['E', 'E', 'M', 'E', 'E'],
21+
['E', 'E', 'm', 'E', 'E'],
2222
['E', 'E', 'E', 'E', 'E'],
2323
['E', 'E', 'E', 'E', 'E']]
2424
@@ -27,7 +27,7 @@ If an empty square ('E') with at least one adjacent mine is revealed, then chang
2727
Output:
2828
2929
[['B', '1', 'E', '1', 'B'],
30-
['B', '1', 'M', '1', 'B'],
30+
['B', '1', 'm', '1', 'B'],
3131
['B', '1', '1', '1', 'B'],
3232
['B', 'B', 'B', 'B', 'B']]
3333
@@ -37,7 +37,7 @@ If an empty square ('E') with at least one adjacent mine is revealed, then chang
3737
Input:
3838
3939
[['B', '1', 'E', '1', 'B'],
40-
['B', '1', 'M', '1', 'B'],
40+
['B', '1', 'm', '1', 'B'],
4141
['B', '1', '1', '1', 'B'],
4242
['B', 'B', 'B', 'B', 'B']]
4343
@@ -54,7 +54,7 @@ If an empty square ('E') with at least one adjacent mine is revealed, then chang
5454
5555
Note:
5656
The range of the input matrix's height and width is [1,50].
57-
The click position will only be an unrevealed square ('M' or 'E'), which also means the input board contains at least one clickable square.
57+
The click position will only be an unrevealed square ('m' or 'E'), which also means the input board contains at least one clickable square.
5858
The input board won't be a stage when game is over (some mines have been revealed).
5959
For simplicity, not mentioned rules should be ignored in this problem. For example, you don't need to reveal all the unrevealed mines when the game is over, consider any cases that you will win the game or flag any squares.
6060
*/

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C.
99
* And we defined a friend circle is a group of students who are direct or indirect friends.
1010
11-
Given a N*N matrix M representing the friend relationship between students in the class.
12-
If M[i][j] = 1, then the ith and jth students are direct friends with each other, otherwise not.
11+
Given a N*N matrix m representing the friend relationship between students in the class.
12+
If m[i][j] = 1, then the ith and jth students are direct friends with each other, otherwise not.
1313
And you have to output the total number of friend circles among all the students.
1414
1515
Example 1:
@@ -32,8 +32,8 @@
3232
3333
Note:
3434
N is in range [1,200].
35-
M[i][i] = 1 for all students.
36-
If M[i][j] = 1, then M[j][i] = 1.
35+
m[i][i] = 1 for all students.
36+
If m[i][j] = 1, then m[j][i] = 1.
3737
*/
3838
public class _547 {
3939

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**Longest Line of Consecutive One in Matrix
88
*
9-
* Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horizontal, vertical, diagonal or anti-diagonal.
9+
* Given a 01 matrix m, find the longest line of consecutive one in the matrix. The line could be horizontal, vertical, diagonal or anti-diagonal.
1010
1111
Example:
1212

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/**
44
* 598. Range Addition II
55
6-
Given an m * n matrix M initialized with all 0's and several update operations.
6+
Given an m * n matrix m initialized with all 0's and several update operations.
77
Operations are represented by a 2D array,
88
and each operation is represented by an array with two positive integers a and b,
9-
which means M[i][j] should be added by one for all 0 <= i < a and 0 <= j < b.
9+
which means m[i][j] should be added by one for all 0 <= i < a and 0 <= j < b.
1010
1111
You need to count and return the number of maximum integers in the matrix after performing all the operations.
1212
@@ -17,22 +17,22 @@
1717
Output: 4
1818
1919
Explanation:
20-
Initially, M =
20+
Initially, m =
2121
[[0, 0, 0],
2222
[0, 0, 0],
2323
[0, 0, 0]]
2424
25-
After performing [2,2], M =
25+
After performing [2,2], m =
2626
[[1, 1, 0],
2727
[1, 1, 0],
2828
[0, 0, 0]]
2929
30-
After performing [3,3], M =
30+
After performing [3,3], m =
3131
[[2, 2, 1],
3232
[2, 2, 1],
3333
[1, 1, 1]]
3434
35-
So the maximum integer in M is 2, and there are four of it in M. So return 4.
35+
So the maximum integer in m is 2, and there are four of it in m. So return 4.
3636
Note:
3737
The range of m and n is [1,40000].
3838
The range of a is [1,m], and the range of b is [1,n].

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class _631 {
8282
/**Credit: https://leetcode.com/articles/design-excel-sum-formula/#approach-1-using-topological-sortaccepted*/
8383
public static class Excel {
8484

85-
Formula[][] Formulas;
85+
Formula[][] formulas;
8686

8787
class Formula {
8888
Formula(HashMap<String, Integer> c, int v) {
@@ -97,18 +97,18 @@ class Formula {
9797
Stack<int[]> stack = new Stack<>();
9898

9999
public Excel(int H, char W) {
100-
Formulas = new Formula[H][(W - 'A') + 1];
100+
formulas = new Formula[H][(W - 'A') + 1];
101101
}
102102

103103
public int get(int r, char c) {
104-
if (Formulas[r - 1][c - 'A'] == null) {
104+
if (formulas[r - 1][c - 'A'] == null) {
105105
return 0;
106106
}
107-
return Formulas[r - 1][c - 'A'].val;
107+
return formulas[r - 1][c - 'A'].val;
108108
}
109109

110110
public void set(int r, char c, int v) {
111-
Formulas[r - 1][c - 'A'] = new Formula(new HashMap<String, Integer>(), v);
111+
formulas[r - 1][c - 'A'] = new Formula(new HashMap<String, Integer>(), v);
112112
topologicalSort(r - 1, c - 'A');
113113
execute_stack();
114114
}
@@ -117,14 +117,14 @@ public int sum(int r, char c, String[] strs) {
117117
HashMap<String, Integer> cells = convert(strs);
118118
int summ = calculate_sum(r - 1, c - 'A', cells);
119119
set(r, c, summ);
120-
Formulas[r - 1][c - 'A'] = new Formula(cells, summ);
120+
formulas[r - 1][c - 'A'] = new Formula(cells, summ);
121121
return summ;
122122
}
123123

124124
public void topologicalSort(int r, int c) {
125-
for (int i = 0; i < Formulas.length; i++) {
126-
for (int j = 0; j < Formulas[0].length; j++) {
127-
if (Formulas[i][j] != null && Formulas[i][j].cells.containsKey("" + (char) ('A' + c) + (r + 1))) {
125+
for (int i = 0; i < formulas.length; i++) {
126+
for (int j = 0; j < formulas[0].length; j++) {
127+
if (formulas[i][j] != null && formulas[i][j].cells.containsKey("" + (char) ('A' + c) + (r + 1))) {
128128
topologicalSort(i, j);
129129
}
130130
}
@@ -135,8 +135,8 @@ public void topologicalSort(int r, int c) {
135135
public void execute_stack() {
136136
while (!stack.isEmpty()) {
137137
int[] top = stack.pop();
138-
if (Formulas[top[0]][top[1]].cells.size() > 0) {
139-
calculate_sum(top[0], top[1], Formulas[top[0]][top[1]].cells);
138+
if (formulas[top[0]][top[1]].cells.size() > 0) {
139+
calculate_sum(top[0], top[1], formulas[top[0]][top[1]].cells);
140140
}
141141
}
142142
}
@@ -164,9 +164,9 @@ public int calculate_sum(int r, int c, HashMap<String, Integer> cells) {
164164
int sum = 0;
165165
for (String s : cells.keySet()) {
166166
int x = Integer.parseInt(s.substring(1)) - 1, y = s.charAt(0) - 'A';
167-
sum += (Formulas[x][y] != null ? Formulas[x][y].val : 0) * cells.get(s);
167+
sum += (formulas[x][y] != null ? formulas[x][y].val : 0) * cells.get(s);
168168
}
169-
Formulas[r][c] = new Formula(cells, sum);
169+
formulas[r][c] = new Formula(cells, sum);
170170
return sum;
171171
}
172172
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
public class _639 {
3434
/**reference: https://leetcode.com/articles/decode-ways-ii/#approach-2-dynamic-programming-accepted*/
35-
int M = 1000000007;
35+
int m = 1000000007;
3636
public int numDecodings(String s) {
3737
long[] dp = new long[s.length() + 1];
3838
dp[0] = 1;
@@ -41,20 +41,20 @@ public int numDecodings(String s) {
4141
if (s.charAt(i) == '*') {
4242
dp[i + 1] = 9 * dp[i];
4343
if (s.charAt(i - 1) == '1') {
44-
dp[i + 1] = (dp[i + 1] + 9 * dp[i - 1]) % M;
44+
dp[i + 1] = (dp[i + 1] + 9 * dp[i - 1]) % m;
4545
} else if (s.charAt(i - 1) == '2') {
46-
dp[i + 1] = (dp[i + 1] + 6 * dp[i - 1]) % M;
46+
dp[i + 1] = (dp[i + 1] + 6 * dp[i - 1]) % m;
4747
} else if (s.charAt(i - 1) == '*') {
48-
dp[i + 1] = (dp[i + 1] + 15 * dp[i - 1]) % M;
48+
dp[i + 1] = (dp[i + 1] + 15 * dp[i - 1]) % m;
4949
}
5050
} else {
5151
dp[i + 1] = s.charAt(i) != '0' ? dp[i] : 0;
5252
if (s.charAt(i - 1) == '1') {
53-
dp[i + 1] = (dp[i + 1] + dp[i - 1]) % M;
53+
dp[i + 1] = (dp[i + 1] + dp[i - 1]) % m;
5454
} else if (s.charAt(i - 1) == '2' && s.charAt(i) <= '6') {
55-
dp[i + 1] = (dp[i + 1] + dp[i - 1]) % M;
55+
dp[i + 1] = (dp[i + 1] + dp[i - 1]) % m;
5656
} else if (s.charAt(i - 1) == '*') {
57-
dp[i + 1] = (dp[i + 1] + (s.charAt(i) <= '6' ? 2 : 1) * dp[i - 1]) % M;
57+
dp[i + 1] = (dp[i + 1] + (s.charAt(i) <= '6' ? 2 : 1) * dp[i - 1]) % m;
5858
}
5959
}
6060
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* 661. Image Smoother
55
*
6-
* Given a 2D integer matrix M representing the gray scale of an image,
6+
* Given a 2D integer matrix m representing the gray scale of an image,
77
* you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of
88
* all the 8 surrounding cells and itself. If a cell has less than 8 surrounding cells, then use as many as you can.
99

0 commit comments

Comments
 (0)