Skip to content

Commit e8ade59

Browse files
checkstyle fix
1 parent b468b00 commit e8ade59

Some content is hidden

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

45 files changed

+378
-350
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gradle/
2+
gradle/
3+
gradlew
4+
gradlew.bat
5+

build.gradle

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'java'
2+
apply plugin: 'maven'
3+
apply plugin: 'checkstyle'
4+
5+
group = 'com.fishercoder'
6+
version = '1.0-SNAPSHOT'
7+
8+
checkstyle {
9+
//include ( '**/*.java')
10+
configFile = file("${rootDir}/fishercoder_codestyle.xml")
11+
}
12+
13+
description = """"""
14+
15+
sourceCompatibility = 1.8
16+
targetCompatibility = 1.8
17+
18+
19+
20+
repositories {
21+
22+
maven { url "http://repo.maven.apache.org/maven2" }
23+
}
24+
dependencies {
25+
testCompile group: 'junit', name: 'junit', version:'4.12'
26+
}

fishercoder_codestyle.xml

+30-30
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
<property name="eachLine" value="false"/>
3333
</module>-->
3434

35-
<module name="SuppressionCommentFilter">
36-
<property name="offCommentFormat" value="CHECKSTYLE_OFF\: ([\w\|]+)"/>
37-
<property name="onCommentFormat" value="CHECKSTYLE_OFF\: ([\w\|]+)"/>
38-
<property name="checkFormat" value="$1"/>
39-
</module>
35+
<!--<module name="SuppressionCommentFilter">-->
36+
<!--<property name="offCommentFormat" value="CHECKSTYLE_OFF\: ([\w\|]+)"/>-->
37+
<!--<property name="onCommentFormat" value="CHECKSTYLE_OFF\: ([\w\|]+)"/>-->
38+
<!--<property name="checkFormat" value="$1"/>-->
39+
<!--</module>-->
4040

4141
<module name="TreeWalker">
4242
<property name="tabWidth" value="4"/>
@@ -53,7 +53,7 @@
5353
</module> -->
5454
<module name="LineLength">
5555
<!--change it to 100 later-->
56-
<property name="max" value="1000"/>
56+
<property name="max" value="1000000"/>
5757
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
5858
</module>
5959
<!-- <module name="AvoidStarImport"/> -->
@@ -84,28 +84,28 @@
8484
<!--value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>-->
8585
<!--</module>-->
8686
<!--<module name="OneStatementPerLine"/>-->
87-
<module name="MultipleVariableDeclarations"/>
88-
<module name="ArrayTypeStyle"/>
89-
<module name="MissingSwitchDefault"/>
87+
<!--<module name="MultipleVariableDeclarations"/>-->
88+
<!--<module name="ArrayTypeStyle"/>-->
89+
<!--<module name="MissingSwitchDefault"/>-->
9090
<module name="FallThrough"/>
9191
<module name="UpperEll"/>
9292
<module name="ModifierOrder"/>
93-
<module name="EmptyLineSeparator">
94-
<property name="allowNoEmptyLineBetweenFields" value="true"/>
95-
</module>
96-
<module name="SeparatorWrap">
97-
<property name="tokens" value="DOT"/>
98-
<property name="option" value="nl"/>
99-
</module>
93+
<!--<module name="EmptyLineSeparator">-->
94+
<!--<property name="allowNoEmptyLineBetweenFields" value="true"/>-->
95+
<!--</module>-->
96+
<!--<module name="SeparatorWrap">-->
97+
<!--<property name="tokens" value="DOT"/>-->
98+
<!--<property name="option" value="nl"/>-->
99+
<!--</module>-->
100100
<module name="SeparatorWrap">
101101
<property name="tokens" value="COMMA"/>
102102
<property name="option" value="EOL"/>
103103
</module>
104-
<module name="PackageName">
105-
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
106-
<message key="name.invalidPattern"
107-
value="Package name ''{0}'' must match pattern ''{1}''."/>
108-
</module>
104+
<!--<module name="PackageName">-->
105+
<!--<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>-->
106+
<!--<message key="name.invalidPattern"-->
107+
<!--value="Package name ''{0}'' must match pattern ''{1}''."/>-->
108+
<!--</module>-->
109109
<!--<module name="TypeName">-->
110110
<!--<message key="name.invalidPattern"-->
111111
<!--value="Type name ''{0}'' must match pattern ''{1}''."/>-->
@@ -161,9 +161,9 @@
161161
<property name="allowedAbbreviationLength" value="10"/>
162162
</module>
163163
<!--<module name="OverloadMethodsDeclarationOrder"/>-->
164-
<module name="VariableDeclarationUsageDistance">
165-
<property name="allowedDistance" value="20"/>
166-
</module>
164+
<!--<module name="VariableDeclarationUsageDistance">-->
165+
<!--<property name="allowedDistance" value="20"/>-->
166+
<!--</module>-->
167167
<module name="MethodParamPad"/>
168168
<module name="OperatorWrap">
169169
<property name="option" value="NL"/>
@@ -196,14 +196,14 @@
196196
<property name="allowedAnnotations" value="Override, Test"/>
197197
<property name="allowThrowsTagsForSubclasses" value="true"/>
198198
</module>-->
199-
<module name="MethodName">
200-
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
201-
<message key="name.invalidPattern"
202-
value="Method name ''{0}'' must match pattern ''{1}''."/>
203-
</module>
199+
<!--<module name="MethodName">-->
200+
<!--<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>-->
201+
<!--<message key="name.invalidPattern"-->
202+
<!--value="Method name ''{0}'' must match pattern ''{1}''."/>-->
203+
<!--</module>-->
204204
<module name="MethodLength">
205205
<property name="tokens" value="METHOD_DEF"/>
206-
<property name="max" value="100"/>
206+
<property name="max" value="200000"/>
207207
<property name="countEmpty" value="false"/>
208208
</module>
209209
<!--<module name="SingleLineJavadoc"/> -->

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'leetcode-algorithms'

src/main/java/com/fishercoder/common/utils/BTreePrinter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,15 @@ private static Node<Integer> test2() {
166166

167167
return root;
168168
}
169-
}
170169

171-
class Node<T extends Comparable<?>> {
170+
171+
public static class Node<T extends Comparable<?>> {
172172
Node<T> left, right;
173173
T data;
174174

175175
public Node(T data) {
176176
this.data = data;
177177
}
178178
}
179+
180+
}

src/main/java/com/fishercoder/common/utils/TreeUtils.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class TreeUtils {
2626
1
2727
2828
*/
29-
@Notes(context = "This is usually how Leetcode OJ passes a binary tree into testing: " +
30-
"https://leetcode.com/faq/#binary-tree, I wrote this function for my own ease of testing when copying" +
31-
"the test case from Leetcode in the form of [1, null, 2, 3].")
29+
@Notes(context = "This is usually how Leetcode OJ passes a binary tree into testing: "
30+
+ "https://leetcode.com/faq/#binary-tree, I wrote this function for my own ease of testing when copying"
31+
+ "the test case from Leetcode in the form of [1, null, 2, 3].")
3232
public static TreeNode constructBinaryTree(List<Integer> treeValues) {
3333
TreeNode root = new TreeNode(treeValues.get(0));
3434
Queue<TreeNode> queue = new LinkedList<>();
@@ -136,17 +136,17 @@ private static void inOrder(TreeNode root) {
136136
inOrder(root.right);
137137
}
138138

139-
public static void main (String... args){
140-
//test random int generator
139+
public static void main(String... args) {
140+
//test random int generator
141141
List<Integer> treeValues = CommonUtils.randomIntArrayGenerator(24);
142-
142+
143143
List<Integer> treeValues2 = Arrays.asList(0, 1, 2, 3, 4, 5, 6);
144-
144+
145145
//test tree construction
146146
// TreeNode root1 = bruteForceConstructBinaryTree(treeValues2);
147147
// inOrderTraversal(root1);
148148
// printBinaryTree(root1);
149-
149+
150150
// test tree construction
151151
TreeNode root2 = constructBinaryTree(treeValues);
152152
inOrderTraversal(root2);
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package com.fishercoder.solutions;
22

3-
/**Given an integer, convert it to a roman numeral.
4-
5-
Input is guaranteed to be within the range from 1 to 3999.*/
3+
/**
4+
* Given an integer, convert it to a roman numeral.
5+
* Input is guaranteed to be within the range from 1 to 3999.
6+
*/
67
public class _12 {
78
//looked at this post: https://discuss.leetcode.com/topic/12384/simple-solution
89
public String intToRoman(int num) {
9-
String M[] = {"", "M", "MM", "MMM"};
10+
String M[] = new String[]{"", "M", "MM", "MMM"};
1011
String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
1112
String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
1213
String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
13-
return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10];
14+
return M[num / 1000] + C[(num % 1000) / 100] + X[(num % 100) / 10] + I[num % 10];
1415
}
1516

1617
}

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

+14-13
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@
22

33
import java.util.Arrays;
44

5-
/**Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.
6-
For example, given array S = {-1 2 1 -4}, and target = 1.
7-
The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).*/
5+
/**
6+
* Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.
7+
* For example, given array S = {-1 2 1 -4}, and target = 1.
8+
* The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
9+
*/
810

911
public class _16 {
1012

1113
public int threeSumClosest(int[] nums, int target) {
12-
if(nums == null || nums.length == 0) return 0;
14+
if (nums == null || nums.length == 0) return 0;
1315
Arrays.sort(nums);
1416
int len = nums.length;
15-
if(len < 3){
17+
if (len < 3) {
1618
int sum = 0;
17-
for(int i : nums){
19+
for (int i : nums) {
1820
sum += i;
1921
}
2022
return sum;
2123
}
2224
int sum = nums[0] + nums[1] + nums[2];
23-
for(int i = 0; i < nums.length-2; i++){
24-
int left = i+1, right = nums.length-1;
25-
while(left < right){
25+
for (int i = 0; i < nums.length - 2; i++) {
26+
int left = i + 1, right = nums.length - 1;
27+
while (left < right) {
2628
int thisSum = nums[i] + nums[left] + nums[right];
27-
if(Math.abs(target - thisSum) < Math.abs(target - sum)) {
29+
if (Math.abs(target - thisSum) < Math.abs(target - sum)) {
2830
sum = thisSum;
29-
if(sum == target) return sum;
30-
}
31-
else if(target > thisSum){
31+
if (sum == target) return sum;
32+
} else if (target > thisSum) {
3233
left++;
3334
} else {
3435
right--;

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
/**
77
* Given a sorted integer array where the range of elements are in the inclusive range [lower, upper], return its missing ranges.
8-
9-
For example, given [0, 1, 3, 50, 75], lower = 0 and upper = 99, return ["2", "4->49", "51->74", "76->99"].
8+
* <p>
9+
* For example, given [0, 1, 3, 50, 75], lower = 0 and upper = 99, return ["2", "4->49", "51->74", "76->99"].
1010
*/
1111
public class _163 {
1212

@@ -19,9 +19,8 @@ public List<String> findMissingRanges(int[] nums, int lower, int upper) {
1919
if (nums.length == 0) {
2020
res.add(getRange(lower, longUpper));
2121
return res;
22-
}
23-
else if (nums.length == 1 && nums[0] == -2147483648 && lower == -2147483648 && upper == 2147483647){
24-
res.add(getRange(lower+1, longUpper));
22+
} else if (nums.length == 1 && nums[0] == -2147483648 && lower == -2147483648 && upper == 2147483647) {
23+
res.add(getRange(lower + 1, longUpper));
2524
return res;
2625
}
2726

@@ -44,8 +43,10 @@ else if (nums.length == 1 && nums[0] == -2147483648 && lower == -2147483648 && u
4443
}
4544

4645
// do a final check
47-
if (next > Integer.MIN_VALUE && next <= longUpper && longUpper < Integer.MAX_VALUE) res.add(getRange(next, longUpper));
48-
if (next == Integer.MIN_VALUE && longUpper == Integer.MAX_VALUE && nums.length == 0) res.add(getRange(next, longUpper));
46+
if (next > Integer.MIN_VALUE && next <= longUpper && longUpper < Integer.MAX_VALUE)
47+
res.add(getRange(next, longUpper));
48+
if (next == Integer.MIN_VALUE && longUpper == Integer.MAX_VALUE && nums.length == 0)
49+
res.add(getRange(next, longUpper));
4950

5051
return res;
5152
}

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

+19-19
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88

99
/**
1010
* 170. Two Sum III - Data structure design
11-
*
11+
* <p>
1212
* Design and implement a _1 class. It should support the following operations: add and find.
13-
14-
add - Add the number to an internal data structure.
15-
find - Find if there exists any pair of numbers which sum is equal to the value.
16-
17-
For example,
18-
add(1); add(3); add(5);
19-
find(4) -> true
20-
find(7) -> false*/
13+
* <p>
14+
* add - Add the number to an internal data structure.
15+
* find - Find if there exists any pair of numbers which sum is equal to the value.
16+
* <p>
17+
* For example,
18+
* add(1); add(3); add(5);
19+
* find(4) -> true
20+
* find(7) -> false
21+
*/
2122

2223
//Your _1 object will be instantiated and called as such:
2324
//_1 twoSum = new _1();
@@ -26,23 +27,22 @@
2627
public class _170 {
2728
private Map<Integer, Integer> map = new HashMap();
2829
private List<Integer> list = new ArrayList();
29-
30-
// Add the number to an internal data structure.
30+
31+
// Add the number to an internal data structure.
3132
public void add(int number) {
3233
list.add(number);
33-
map.put(number, map.getOrDefault(number, 0)+1);
34+
map.put(number, map.getOrDefault(number, 0) + 1);
3435
}
3536

3637
// Find if there exists any pair of numbers which sum is equal to the value.
3738
public boolean find(int value) {
38-
for(int i = 0; i < list.size(); i++){
39+
for (int i = 0; i < list.size(); i++) {
3940
int val1 = list.get(i);
40-
int val2 = value-val1;
41-
if(map.containsKey(val2)) {
42-
if(val1 == val2) {
43-
if(map.get(val2) > 1) return true;
44-
}
45-
else return true;
41+
int val2 = value - val1;
42+
if (map.containsKey(val2)) {
43+
if (val1 == val2) {
44+
if (map.get(val2) > 1) return true;
45+
} else return true;
4646
}
4747
}
4848
return false;

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,23 @@ public List<int[]> getSkyline(int[][] buildings) {
8989
TreeMap<Integer, Integer> treeMap = new TreeMap();
9090
treeMap.put(0, 1);
9191
int prevMaxH = 0;
92-
for(BuildingPoint bp : bps){
92+
for (BuildingPoint bp : bps) {
9393
//if it's a starting point, we'll add it into the final result
94-
if(bp.isStart){
95-
if(treeMap.containsKey(bp.h)) treeMap.put(bp.h, treeMap.get(bp.h)+1);
94+
if (bp.isStart) {
95+
if (treeMap.containsKey(bp.h)) treeMap.put(bp.h, treeMap.get(bp.h) + 1);
9696
else treeMap.put(bp.h, 1);
97-
}
98-
99-
//if it's an ending point, we'll decrement/remove this entry
100-
else if(!bp.isStart){
101-
if(treeMap.containsKey(bp.h) && treeMap.get(bp.h) > 1) treeMap.put(bp.h, treeMap.get(bp.h)-1);
97+
} else if (!bp.isStart) {
98+
//if it's an ending point, we'll decrement/remove this entry
99+
if (treeMap.containsKey(bp.h) && treeMap.get(bp.h) > 1) treeMap.put(bp.h, treeMap.get(bp.h) - 1);
102100
else treeMap.remove(bp.h);
103101
}
104-
102+
105103
int currMaxH = treeMap.lastKey();
106-
if(currMaxH != prevMaxH){
104+
if (currMaxH != prevMaxH) {
107105
result.add(new int[]{bp.x, currMaxH});
108-
prevMaxH = currMaxH;
106+
prevMaxH = currMaxH;
109107
}
110-
108+
111109
}
112110

113111
return result;

0 commit comments

Comments
 (0)