Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bf7229a

Browse files
enable OverloadMethodsDeclarationOrder
1 parent dbc923b commit bf7229a

File tree

3 files changed

+60
-67
lines changed

3 files changed

+60
-67
lines changed

fishercoder_checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
<property name="ignoreFinal" value="false"/>
163163
<property name="allowedAbbreviationLength" value="10"/>
164164
</module>
165-
<!--<module name="OverloadMethodsDeclarationOrder"/>-->
165+
<module name="OverloadMethodsDeclarationOrder"/>
166166
<!--<module name="VariableDeclarationUsageDistance">-->
167167
<!--<property name="allowedDistance" value="20"/>-->
168168
<!--</module>-->

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

+22-22
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public static void print(int num) {
4040
System.out.print(num);
4141
}
4242

43+
public static void print(List<String> list) {
44+
System.out.println("----------------------------------------------------");
45+
for (String str : list) {
46+
System.out.print(str + ", ");
47+
}
48+
System.out.println();
49+
}
50+
4351
public static void println(String message) {
4452
System.out.println(message);
4553
}
@@ -138,6 +146,20 @@ public static void printList(final ListNode head) {
138146
System.out.println();
139147
}
140148

149+
public static <T> void printList(List<T> list) {
150+
int count = 0;
151+
for (T t : list) {
152+
count++;
153+
System.out.print(t);
154+
if (count % 10 != 0) {
155+
System.out.print("\t");
156+
} else {
157+
System.out.println();
158+
}
159+
}
160+
System.out.println();
161+
}
162+
141163
public static void printMatrix(int[][] matrix) {
142164
System.out.println("Matrix is: ");
143165
for (int i = 0; i < matrix.length; i++) {
@@ -162,14 +184,6 @@ public static void printMatrixGeneric(boolean[][] matrix) {
162184

163185
}
164186

165-
public static void print(List<String> list) {
166-
System.out.println("----------------------------------------------------");
167-
for (String str : list) {
168-
System.out.print(str + ", ");
169-
}
170-
System.out.println();
171-
}
172-
173187
public static <T> void printListList(List<List<T>> res) {
174188
for (List<T> list : res) {
175189
for (T i : list) {
@@ -179,20 +193,6 @@ public static <T> void printListList(List<List<T>> res) {
179193
}
180194
}
181195

182-
public static <T> void printList(List<T> list) {
183-
int count = 0;
184-
for (T t : list) {
185-
count++;
186-
System.out.print(t);
187-
if (count % 10 != 0) {
188-
System.out.print("\t");
189-
} else {
190-
System.out.println();
191-
}
192-
}
193-
System.out.println();
194-
}
195-
196196
public static void printIntervals(List<Interval> intervals) {
197197
for (Interval interval : intervals) {
198198
System.out.print("[" + interval.start + ", " + interval.end + "], ");
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fishercoder.solutions;
22

33
import com.fishercoder.common.classes.TreeNode;
4-
import com.fishercoder.common.utils.CommonUtils;
54

65
import java.util.ArrayList;
76
import java.util.List;
@@ -23,52 +22,46 @@
2322
*/
2423

2524
public class _257 {
26-
//a very typical/good question to test your recursion/dfs understanding.
27-
public List<String> binaryTreePaths_more_concise(TreeNode root) {
28-
List<String> paths = new ArrayList<String>();
29-
if(root == null) return paths;
30-
dfs(root, paths, "");
31-
return paths;
32-
}
33-
34-
private void dfs(TreeNode root, List<String> paths, String path) {
35-
if(root.left == null && root.right == null){
36-
paths.add(path + root.val);
37-
return;
25+
public static class Solution1 {
26+
//a very typical/good question to test your recursion/dfs understanding.
27+
public List<String> binaryTreePaths_more_concise(TreeNode root) {
28+
List<String> paths = new ArrayList<String>();
29+
if (root == null) return paths;
30+
dfs(root, paths, "");
31+
return paths;
3832
}
39-
path += root.val + "->";
40-
if(root.left != null) dfs(root.left, paths, path);
41-
if(root.right != null) dfs(root.right, paths, path);
42-
}
43-
44-
public static void main(String...strings){
45-
_257 test = new _257();
46-
TreeNode root = new TreeNode(1);
47-
root.left = new TreeNode(2);
48-
root.left.right = new TreeNode(5);
49-
root.right = new TreeNode(3);
50-
List<String> res = test.binaryTreePaths(root);
51-
CommonUtils.print(res);
52-
}
5333

54-
public List<String> binaryTreePaths(TreeNode root) {
55-
List<String> paths = new ArrayList<String>();
56-
dfs(root, paths, new StringBuilder());
57-
return paths;
34+
private void dfs(TreeNode root, List<String> paths, String path) {
35+
if (root.left == null && root.right == null) {
36+
paths.add(path + root.val);
37+
return;
38+
}
39+
path += root.val + "->";
40+
if (root.left != null) dfs(root.left, paths, path);
41+
if (root.right != null) dfs(root.right, paths, path);
42+
}
5843
}
44+
45+
public static class Solution2 {
46+
public List<String> binaryTreePaths(TreeNode root) {
47+
List<String> paths = new ArrayList<String>();
48+
dfs(root, paths, new StringBuilder());
49+
return paths;
50+
}
5951

60-
private void dfs(TreeNode root, List<String> paths, StringBuilder sb) {
61-
if(root == null) return;
62-
if(root.left == null && root.right == null){
63-
sb.append(root.val);
64-
paths.add(sb.toString());
65-
return ;
66-
}
67-
sb.append(root.val + "->");
68-
String curr = sb.toString();
69-
if(root.left != null) dfs(root.left, paths, sb);
70-
sb.setLength(0);
71-
sb.append(curr);
72-
if(root.right != null) dfs(root.right, paths, sb);
52+
private void dfs(TreeNode root, List<String> paths, StringBuilder sb) {
53+
if (root == null) return;
54+
if (root.left == null && root.right == null) {
55+
sb.append(root.val);
56+
paths.add(sb.toString());
57+
return;
58+
}
59+
sb.append(root.val + "->");
60+
String curr = sb.toString();
61+
if (root.left != null) dfs(root.left, paths, sb);
62+
sb.setLength(0);
63+
sb.append(curr);
64+
if (root.right != null) dfs(root.right, paths, sb);
65+
}
7366
}
7467
}

0 commit comments

Comments
 (0)