Skip to content

Commit febbeb7

Browse files
refactor for format
1 parent 21b17c5 commit febbeb7

Some content is hidden

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

49 files changed

+378
-135
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ public Cell(int row, int col, int height) {
4141
}
4242

4343
public int trapRainWater(int[][] heights) {
44-
if (heights == null || heights.length == 0 || heights[0].length == 0)
44+
if (heights == null || heights.length == 0 || heights[0].length == 0) {
4545
return 0;
46+
}
4647

4748
PriorityQueue<Cell> queue = new PriorityQueue<>(1, (a, b) -> a.height - b.height);
4849

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public void abbrGenerator(String target, int i, String tmp, int abbr, int num) {
108108
}
109109
return;
110110
}
111-
if (num <= 0) return;
111+
if (num <= 0) {
112+
return;
113+
}
112114
char cur = target.charAt(i);
113115
abbrGenerator(target, i + 1, abbr == 0 ? tmp + cur : tmp + abbr + cur, 0, abbr == 0 ? num - 1 : num - 2);
114116
abbrGenerator(target, i + 1, tmp, abbr + 1, num);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ public int numberOfArithmeticSlices(int[] A) {
3434
if (A[i] - A[i - 1] == A[i - 1] - A[i - 2]) {
3535
len++;
3636
} else {
37-
if (len > 2) sum += calculateSlices(len);
37+
if (len > 2) {
38+
sum += calculateSlices(len);
39+
}
3840
len = 2;//reset it to 2
3941
}
4042
}
41-
if (len > 2) sum += calculateSlices(len);
43+
if (len > 2) {
44+
sum += calculateSlices(len);
45+
}
4246
return sum;
4347
}
4448

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public static class Solution1 {
1818
* reference: https://discuss.leetcode.com/topic/22976/my-accepted-java-solution
1919
*/
2020
public int trap(int[] height) {
21-
if (height == null || height.length <= 2) return 0;
21+
if (height == null || height.length <= 2) {
22+
return 0;
23+
}
2224

2325
int max = height[0];
2426
int maxIndex = 0;

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ public int strongPasswordChecker(String s) {
1919
int[] arr = new int[carr.length];
2020

2121
for (int i = 0; i < arr.length;) {
22-
if (Character.isLowerCase(carr[i]))
22+
if (Character.isLowerCase(carr[i])) {
2323
a = 0;
24-
if (Character.isUpperCase(carr[i]))
24+
}
25+
if (Character.isUpperCase(carr[i])) {
2526
A = 0;
26-
if (Character.isDigit(carr[i]))
27+
}
28+
if (Character.isDigit(carr[i])) {
2729
d = 0;
30+
}
2831

2932
int j = i;
30-
while (i < carr.length && carr[i] == carr[j]) i++;
33+
while (i < carr.length && carr[i] == carr[j]) {
34+
i++;
35+
}
3136
arr[j] = i - j;
3237
}
3338

@@ -42,7 +47,9 @@ public int strongPasswordChecker(String s) {
4247

4348
for (int k = 1; k < 3; k++) {
4449
for (int i = 0; i < arr.length && overLen > 0; i++) {
45-
if (arr[i] < 3 || arr[i] % 3 != (k - 1)) continue;
50+
if (arr[i] < 3 || arr[i] % 3 != (k - 1)) {
51+
continue;
52+
}
4653
arr[i] -= Math.min(overLen, k);
4754
overLen -= k;
4855
}
@@ -55,7 +62,9 @@ public int strongPasswordChecker(String s) {
5562
overLen -= need;
5663
}
5764

58-
if (arr[i] >= 3) leftOver += arr[i] / 3;
65+
if (arr[i] >= 3) {
66+
leftOver += arr[i] / 3;
67+
}
5968
}
6069

6170
res += Math.max(totalMissing, leftOver);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,15 @@ public boolean validWordSquare(List<String> words) {
7575
for (int i = 0; i < words.size(); i++) {
7676
String word = words.get(i);
7777
for (int j = 0; j < word.length(); j++) {
78-
if (j >= words.size()) return false;
79-
if (i >= words.get(j).length()) return false;
80-
if (word.charAt(j) != words.get(j).charAt(i)) return false;
78+
if (j >= words.size()) {
79+
return false;
80+
}
81+
if (i >= words.get(j).length()) {
82+
return false;
83+
}
84+
if (word.charAt(j) != words.get(j).charAt(i)) {
85+
return false;
86+
}
8187
}
8288
}
8389
return true;

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

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,36 @@ public String originalDigits(String s) {
3131
* we'll have to dedupe for counts[3], counts[5], counts[7] first before we dedupe counts[1] and counts[9].*/
3232
int[] counts = new int[10];
3333
for (int i = 0; i < s.length(); i++) {
34-
if (s.charAt(i) == 'o') counts[1]++;//2,4,0
35-
if (s.charAt(i) == 'w') counts[2]++;
36-
if (s.charAt(i) == 'h') counts[3]++;//8
37-
if (s.charAt(i) == 'u') counts[4]++;
38-
if (s.charAt(i) == 'f') counts[5]++;//4
39-
if (s.charAt(i) == 'x') counts[6]++;
40-
if (s.charAt(i) == 'v') counts[7]++;//5
41-
if (s.charAt(i) == 'g') counts[8]++;
42-
if (s.charAt(i) == 'i') counts[9]++;//5,6,8
43-
if (s.charAt(i) == 'z') counts[0]++;
34+
if (s.charAt(i) == 'o') {
35+
counts[1]++;//2,4,0
36+
}
37+
if (s.charAt(i) == 'w') {
38+
counts[2]++;
39+
}
40+
if (s.charAt(i) == 'h') {
41+
counts[3]++;//8
42+
}
43+
if (s.charAt(i) == 'u') {
44+
counts[4]++;
45+
}
46+
if (s.charAt(i) == 'f') {
47+
counts[5]++;//4
48+
}
49+
if (s.charAt(i) == 'x') {
50+
counts[6]++;
51+
}
52+
if (s.charAt(i) == 'v') {
53+
counts[7]++;//5
54+
}
55+
if (s.charAt(i) == 'g') {
56+
counts[8]++;
57+
}
58+
if (s.charAt(i) == 'i') {
59+
counts[9]++;//5,6,8
60+
}
61+
if (s.charAt(i) == 'z') {
62+
counts[0]++;
63+
}
4464
}
4565

4666
counts[3] -= counts[8];

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public int characterReplacement(String s, int k) {
5555
//this one can pass all test from test1 to test5, but tests like test6 won't pass
5656
public int characterReplacement_failed_attempt(String s, int k) {
5757
int longest = 0;
58-
if (s == null || s.length() == 0) return 0;
58+
if (s == null || s.length() == 0) {
59+
return 0;
60+
}
5961
for (int i = 0; i < s.length(); i++) {
6062
int count = 1;
6163
char val = s.charAt(i);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public class _43 {
1919
* Basically, the rule we can find is that products of each two digits will land in this position in the final product:
2020
* i+j and i+j+1*/
2121
public String multiply(String num1, String num2) {
22-
if (isZero(num1) || isZero(num2)) return "0";
22+
if (isZero(num1) || isZero(num2)) {
23+
return "0";
24+
}
2325
int[] a1 = new int[num1.length()];
2426
int[] a2 = new int[num2.length()];
2527
int[] product = new int[num1.length() + num2.length()];
@@ -42,15 +44,19 @@ public String multiply(String num1, String num2) {
4244

4345
StringBuilder stringBuilder = new StringBuilder();
4446
for (int i = 0; i < product.length; i++) {
45-
if (i == 0 && product[i] == 0) continue;
47+
if (i == 0 && product[i] == 0) {
48+
continue;
49+
}
4650
stringBuilder.append(product[i]);
4751
}
4852
return stringBuilder.toString();
4953
}
5054

5155
private boolean isZero(String num) {
5256
for (char c : num.toCharArray()) {
53-
if (c != '0') return false;
57+
if (c != '0') {
58+
return false;
59+
}
5460
}
5561
return true;
5662
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ public void inc(String key) {
6565
changeKey(key, 1);
6666
} else {
6767
keyCountMap.put(key, 1);
68-
if (head.next.count != 1)
68+
if (head.next.count != 1) {
6969
addBucketAfter(new Bucket(1), head);
70+
}
7071
head.next.keySet.add(key);
7172
countBucketMap.put(1, head.next);
7273
}

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