Skip to content

Commit eb1805a

Browse files
refactor for format
1 parent 21969f1 commit eb1805a

File tree

3 files changed

+34
-53
lines changed

3 files changed

+34
-53
lines changed

fishercoder_checkstyle.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@
2626

2727
<property name="severity" value="error"/>
2828

29-
<!--this cannot be enabled because right now Intellij CE cannot import my fishercoder_checkstyle.xml as -->
30-
<!--my chosen Java code style-->
31-
<!-- Checks for whitespace -->
32-
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
33-
<!--<module name="FileTabCharacter">-->
34-
<!--<property name="eachLine" value="false"/>-->
35-
<!--</module>-->
36-
3729
<module name="SuppressionCommentFilter">
3830
<property name="offCommentFormat" value="CHECKSTYLE_OFF\: ([\w\|]+)"/>
3931
<property name="onCommentFormat" value="CHECKSTYLE_OFF\: ([\w\|]+)"/>
@@ -184,16 +176,6 @@
184176
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
185177
</module>
186178

187-
<!--I need to import this .xml format as my Intellij Java codestyle to make it work-->
188-
<!--<module name="Indentation">-->
189-
<!--<property name="basicOffset" value="4"/>-->
190-
<!--<property name="braceAdjustment" value="0"/>-->
191-
<!--<property name="caseIndent" value="4"/>-->
192-
<!--<property name="throwsIndent" value="4"/>-->
193-
<!--<property name="lineWrappingIndentation" value="4"/>-->
194-
<!--<property name="arrayInitIndent" value="4"/>-->
195-
<!--</module>-->
196-
197179
<module name="AbbreviationAsWordInName">
198180
<property name="ignoreFinal" value="false"/>
199181
<property name="allowedAbbreviationLength" value="10"/>

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.List;
1010
import java.util.Queue;
1111

12-
1312
/**
1413
* This is a util class to contain all tree related methods.
1514
*/
@@ -26,8 +25,8 @@ public class TreeUtils {
2625
1
2726
*/
2827
@Notes(context = "This is usually how Leetcode OJ passes a binary tree into testing: "
29-
+ "https://leetcode.com/faq/#binary-tree, I wrote this function for my own ease of testing when copying"
30-
+ "the test case from Leetcode in the form of [1, null, 2, 3].")
28+
+ "https://leetcode.com/faq/#binary-tree, I wrote this function for my own ease of testing when copying"
29+
+ "the test case from Leetcode in the form of [1, null, 2, 3].")
3130
public static TreeNode constructBinaryTree(List<Integer> treeValues) {
3231
TreeNode root = new TreeNode(treeValues.get(0));
3332
Queue<TreeNode> queue = new LinkedList<>();
@@ -61,11 +60,11 @@ private static int maxLevel(TreeNode root) {
6160
}
6261

6362
return Math.max(TreeUtils.maxLevel(root.left),
64-
TreeUtils.maxLevel(root.right)) + 1;
63+
TreeUtils.maxLevel(root.right)) + 1;
6564
}
6665

6766
private static void printNodeInternal(
68-
List<TreeNode> list, int level, int maxLevel) {
67+
List<TreeNode> list, int level, int maxLevel) {
6968
if (list.isEmpty() || CommonUtils.isAllElementsNull(list)) {
7069
return;
7170
}
@@ -98,7 +97,7 @@ private static void printNodeInternal(
9897
CommonUtils.printWhitespaces(firstSpaces - i);
9998
if (list.get(j) == null) {
10099
CommonUtils.printWhitespaces(endgeLines + endgeLines + i
101-
+ 1);
100+
+ 1);
102101
continue;
103102
}
104103

@@ -145,9 +144,9 @@ public static void main(String... args) {
145144
List<Integer> treeValues2 = Arrays.asList(0, 1, 2, 3, 4, 5, 6);
146145

147146
//test tree construction
148-
// TreeNode root1 = bruteForceConstructBinaryTree(treeValues2);
149-
// inOrderTraversal(root1);
150-
// printBinaryTree(root1);
147+
// TreeNode root1 = bruteForceConstructBinaryTree(treeValues2);
148+
// inOrderTraversal(root1);
149+
// printBinaryTree(root1);
151150

152151
// test tree construction
153152
TreeNode root2 = constructBinaryTree(treeValues);
@@ -157,7 +156,7 @@ public static void main(String... args) {
157156
List<Integer> treeVals = new ArrayList<>(Arrays.asList(1, null, 2, 3));
158157
CommonUtils.printList(treeVals);
159158
root2 = constructBinaryTree(treeVals);
160-
// inOrderTraversal(root2);
159+
// inOrderTraversal(root2);
161160
printBinaryTree(root2);
162161
}
163162
}

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@
1515

1616
public class _6 {
1717

18-
public String convert(String s, int numRows) {
19-
StringBuilder[] sb = new StringBuilder[numRows];
20-
char[] c = s.toCharArray();
21-
int len = s.length();
22-
for (int i = 0; i < numRows; i++) {
23-
sb[i] = new StringBuilder();//this is an important step to initialize it
24-
}
25-
int i = 0;
26-
while (i < len) {
27-
for (int index = 0; index < numRows && i < len; index++) {
28-
sb[index].append(c[i++]);// vertically down
29-
}
30-
31-
for (int index = numRows - 2; index >= 1 && i < len; index--) {
32-
/**Why it should start from numRows - 2? Think of the example when numRows = 3
33-
the starting point of obliquely going up is 1, which is numRows-2.*/
34-
sb[index].append(c[i++]);// obliquely up
35-
}
36-
}
37-
38-
for (i = 1; i < numRows; i++) {
39-
sb[0].append(sb[i]);
40-
}
41-
return sb[0].toString();
42-
}
18+
public String convert(String s, int numRows) {
19+
StringBuilder[] sb = new StringBuilder[numRows];
20+
char[] c = s.toCharArray();
21+
int len = s.length();
22+
for (int i = 0; i < numRows; i++) {
23+
sb[i] = new StringBuilder();//this is an important step to initialize it
24+
}
25+
int i = 0;
26+
while (i < len) {
27+
for (int index = 0; index < numRows && i < len; index++) {
28+
sb[index].append(c[i++]);// vertically down
29+
}
30+
31+
for (int index = numRows - 2; index >= 1 && i < len; index--) {
32+
/**Why it should start from numRows - 2? Think of the example when numRows = 3
33+
the starting point of obliquely going up is 1, which is numRows-2.*/
34+
sb[index].append(c[i++]);// obliquely up
35+
}
36+
}
37+
38+
for (i = 1; i < numRows; i++) {
39+
sb[0].append(sb[i]);
40+
}
41+
return sb[0].toString();
42+
}
4343

4444
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy