Skip to content

Commit 0b3a45a

Browse files
refactor for format
1 parent 8090352 commit 0b3a45a

File tree

7 files changed

+52
-18
lines changed

7 files changed

+52
-18
lines changed

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

+24-8
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,37 @@
4242
public class _572 {
4343

4444
public boolean isSubtree(TreeNode s, TreeNode t) {
45-
if (s == null && t == null) return true;
45+
if (s == null && t == null) {
46+
return true;
47+
}
4648
boolean isSubTree = false;
47-
if (s != null && t != null && s.val == t.val) isSubTree = isSameTree(s, t);
48-
if (isSubTree) return true;
49+
if (s != null && t != null && s.val == t.val) {
50+
isSubTree = isSameTree(s, t);
51+
}
52+
if (isSubTree) {
53+
return true;
54+
}
4955
boolean isSubTreeLeft = false;
50-
if (s.left != null) isSubTreeLeft = isSubtree(s.left, t);
51-
if (isSubTreeLeft) return true;
56+
if (s.left != null) {
57+
isSubTreeLeft = isSubtree(s.left, t);
58+
}
59+
if (isSubTreeLeft) {
60+
return true;
61+
}
5262
boolean isSubTreeRight = false;
53-
if (s.right != null) isSubTreeRight = isSubtree(s.right, t);
54-
if (isSubTreeRight) return true;
63+
if (s.right != null) {
64+
isSubTreeRight = isSubtree(s.right, t);
65+
}
66+
if (isSubTreeRight) {
67+
return true;
68+
}
5569
return false;
5670
}
5771

5872
private boolean isSameTree(TreeNode p, TreeNode q) {
59-
if (p == null || q == null) return p == q;
73+
if (p == null || q == null) {
74+
return p == q;
75+
}
6076
return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
6177
}
6278
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public int distributeCandies(int[] candies) {
3131
for (int i = 0; i < candies.length; i++) {
3232
int val = candies[i];
3333
sisCount++;
34-
if (sisCount >= candies.length / 2) return candies.length / 2;
34+
if (sisCount >= candies.length / 2) {
35+
return candies.length / 2;
36+
}
3537
while (i < candies.length && candies[i] == val) {
3638
i++;
3739
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
public class _58 {
1212

1313
public int lengthOfLastWord(String s) {
14-
if (s == null || s.length() == 0) return 0;
14+
if (s == null || s.length() == 0) {
15+
return 0;
16+
}
1517
s = s.trim();
1618
int n = s.length() - 1;
1719
while (n >= 0 && s.charAt(n) != ' ') {

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ public int findUnsortedSubarray(int[] nums) {
3636
for (int i = 1; i < n; i++) {
3737
max = Math.max(max, nums[i]);
3838
min = Math.min(min, nums[n - 1 - i]);
39-
if (nums[i] < max) end = i;
40-
if (nums[n - 1 - i] > min) start = n - 1 - i;
39+
if (nums[i] < max) {
40+
end = i;
41+
}
42+
if (nums[n - 1 - i] > min) {
43+
start = n - 1 - i;
44+
}
4145
}
4246
return end - start + 1;
4347
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public List<Integer> killProcess(List<Integer> pid, List<Integer> ppid, int kill
5454
int curr = stack.poll();
5555
result.add(curr);
5656
List<Integer> list = map.get(curr);
57-
if (list != null) stack.addAll(list);
57+
if (list != null) {
58+
stack.addAll(list);
59+
}
5860
}
5961
return result;
6062
}

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public List<Point> outerTrees(Point[] points) {
6565
Point next = points[0];
6666
int nextIndex = 0;
6767
for (int i = 1; i < points.length; i++) {
68-
if (i == curIndex) continue;
68+
if (i == curIndex) {
69+
continue;
70+
}
6971
int cross = crossProductLength(cur, points[i], next);
7072
if (nextIndex == curIndex || cross > 0
7173
// Handle collinear points
@@ -76,7 +78,9 @@ public List<Point> outerTrees(Point[] points) {
7678
}
7779
// Handle collinear points
7880
for (int i = 0; i < points.length; i++) {
79-
if (i == curIndex) continue;
81+
if (i == curIndex) {
82+
continue;
83+
}
8084
int cross = crossProductLength(cur, points[i], next);
8185
if (cross == 0) {
8286
result.add(points[i]);
@@ -88,7 +92,7 @@ public List<Point> outerTrees(Point[] points) {
8892

8993
} while (curIndex != firstIndex);
9094

91-
return new ArrayList<Point>(result);
95+
return new ArrayList<>(result);
9296
}
9397

9498
private int crossProductLength(Point A, Point B, Point C) {

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ class TrieNode {
6464
TrieNode dfs(String path) {
6565
TrieNode node = root;
6666
for (String eachPath : path.split("/")) {
67-
if (eachPath.isEmpty()) continue;
68-
if (!node.map.containsKey(eachPath)) node.map.put(eachPath, new TrieNode(eachPath));
67+
if (eachPath.isEmpty()) {
68+
continue;
69+
}
70+
if (!node.map.containsKey(eachPath)) {
71+
node.map.put(eachPath, new TrieNode(eachPath));
72+
}
6973
node = node.map.get(eachPath);
7074
}
7175
return node;

0 commit comments

Comments
 (0)