Skip to content

Commit 41f4661

Browse files
refactor for format
1 parent d4c465b commit 41f4661

File tree

14 files changed

+97
-37
lines changed

14 files changed

+97
-37
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
public class _37 {
1111

1212
public void solveSudoku(char[][] board) {
13-
if (board == null || board.length == 0) return;
13+
if (board == null || board.length == 0) {
14+
return;
15+
}
1416
solve(board);
1517
}
1618

@@ -39,10 +41,15 @@ private boolean solve(char[][] board) {
3941

4042
private boolean isValid(char[][] board, int row, int col, char c) {
4143
for (int i = 0; i < 9; i++) {
42-
if (board[i][col] != '.' && board[i][col] == c) return false;//check row
43-
if (board[row][i] != '.' && board[row][i] == c) return false;//check column
44-
if (board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] != '.' && board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c)
44+
if (board[i][col] != '.' && board[i][col] == c) {
45+
return false;//check row
46+
}
47+
if (board[row][i] != '.' && board[row][i] == c) {
48+
return false;//check column
49+
}
50+
if (board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] != '.' && board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c) {
4551
return false; //check 3*3 block
52+
}
4653
}
4754
return true;
4855
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public String countAndSay(int n) {
2626
curr.append(count).append(say);
2727
count = 1;
2828
say = prev.charAt(j);
29-
} else count++;
29+
} else {
30+
count++;
31+
}
3032
}
3133
curr.append(count).append(say);
3234
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public RandomizedSet() {
6868
* Inserts a value to the set. Returns true if the set did not already contain the specified element.
6969
*/
7070
public boolean insert(int val) {
71-
if (forwardMap.containsValue(val)) return false;
72-
else {
71+
if (forwardMap.containsValue(val)) {
72+
return false;
73+
} else {
7374
forwardMap.put(index, val);
7475
reverseMap.put(val, index++);
7576
return true;
@@ -95,7 +96,9 @@ public boolean remove(int val) {
9596
*/
9697
public int getRandom() {
9798
int max = forwardMap.size();
98-
if (max == 1) return forwardMap.get(index - 1);
99+
if (max == 1) {
100+
return forwardMap.get(index - 1);
101+
}
99102
int randomNum = random.nextInt(max);
100103
while (!forwardMap.containsKey(randomNum)) {
101104
randomNum = random.nextInt(max);

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public boolean canConstruct_20160924(String ransomNote, String magazine) {
2424

2525
char[] rchars = ransomNote.toCharArray();
2626
for (int i = 0; i < rchars.length; i++) {
27-
if (mcnt[rchars[i] - 'a'] <= 0) return false;
27+
if (mcnt[rchars[i] - 'a'] <= 0) {
28+
return false;
29+
}
2830
mcnt[rchars[i] - 'a']--;
2931
}
3032
return true;
@@ -48,11 +50,17 @@ public boolean canConstruct(String ransomNote, String magazine) {
4850
}
4951

5052
for (char c : ransomSet) {
51-
if (!magazineSet.contains(c)) return false;
53+
if (!magazineSet.contains(c)) {
54+
return false;
55+
}
5256
}
5357
for (char c : ransomMap.keySet()) {
54-
if (!magazineMap.containsKey(c)) return false;
55-
if (magazineMap.get(c) < ransomMap.get(c)) return false;
58+
if (!magazineMap.containsKey(c)) {
59+
return false;
60+
}
61+
if (magazineMap.get(c) < ransomMap.get(c)) {
62+
return false;
63+
}
5664
}
5765
return true;
5866
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public Solution(int[] nums) {
4545
//insert next value into all possible positions, I wrote this method myself, of course it could be simplified to not use a queue
4646
//but it just naturally came into my mind that I used a queue
4747
private List<List<Integer>> buildAllComb(int[] nums) {
48-
List<List<Integer>> result = new ArrayList<List<Integer>>();
49-
if (nums == null || nums.length == 0) return result;
48+
List<List<Integer>> result = new ArrayList();
49+
if (nums == null || nums.length == 0) {
50+
return result;
51+
}
5052

5153
List<Integer> list = new ArrayList<Integer>();
5254
list.add(nums[0]);
@@ -80,7 +82,9 @@ public int[] reset() {
8082
* Returns a random shuffling of the array.
8183
*/
8284
public int[] shuffle() {
83-
if (original == null || original.length == 0) return original;
85+
if (original == null || original.length == 0) {
86+
return original;
87+
}
8488
int randomIndex = random.nextInt(combinations.size());
8589
List<Integer> list = combinations.get(randomIndex);
8690
int[] result = new int[list.size()];

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public class _385 {
4141
//if it's ']', we'll just pop one nested integer from the working stack and assign it to the result
4242

4343
public NestedInteger deserialize(String s) {
44-
if (s == null || s.isEmpty() || s.length() == 0) return new NestedInteger();
44+
if (s == null || s.isEmpty() || s.length() == 0) {
45+
return new NestedInteger();
46+
}
4547
Stack<NestedInteger> workStack = new Stack<NestedInteger>();
4648
NestedInteger result = null;
4749
StringBuilder sb = new StringBuilder();
@@ -85,10 +87,11 @@ public NestedInteger deserialize(String s) {
8587
}
8688
int num = Integer.parseInt(sb.toString());
8789
NestedInteger ni = null;
88-
if (!workStack.isEmpty())
90+
if (!workStack.isEmpty()) {
8991
ni = workStack.pop();
90-
else
92+
} else {
9193
ni = new NestedInteger();
94+
}
9295
// case 1: if this one contains one integer
9396
if (ni.isInteger()) {
9497
// we'll add it to this ni
@@ -99,12 +102,16 @@ public NestedInteger deserialize(String s) {
99102
ni.add(new NestedInteger(num));
100103
} else {
101104
// case 3: if this is an empty nested integer
102-
if (i > 0) ni.add(new NestedInteger(num));
103-
else ni.setInteger(num);
105+
if (i > 0) {
106+
ni.add(new NestedInteger(num));
107+
} else {
108+
ni.setInteger(num);
109+
}
104110
}
105111
workStack.push(ni);
106-
if (i == s.length())
112+
if (i == s.length()) {
107113
return ni;// this is for test cases like this: "324", there's no '[' or ']'
114+
}
108115
}
109116
}
110117
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public static List lexicalOrder(int n) {
2727
while (i % 10 == 9 || i == n) {
2828
i /= 10;
2929
}
30-
if (i == 0) return result;
30+
if (i == 0) {
31+
return result;
32+
}
3133
i++;
3234
}
3335
}
@@ -44,9 +46,13 @@ public static List lexicalOrder_LTE_by_10458(int n) {
4446
private static List<Integer> addNumbers(List<Integer> result, int insertNumber, int insertPosition, int n) {
4547
int i;
4648
for (i = 0; i < 9; i++) {
47-
if (insertNumber + i > n) return result;
49+
if (insertNumber + i > n) {
50+
return result;
51+
}
4852
result.add(insertPosition + i, insertNumber + i);
49-
if ((insertNumber + i) % 10 == 0 && (insertNumber + i) == (insertNumber + 10)) break;
53+
if ((insertNumber + i) % 10 == 0 && (insertNumber + i) == (insertNumber + 10)) {
54+
break;
55+
}
5056
}
5157
while ((insertNumber + i) % 10 != 0 && (insertNumber + i) <= n) {
5258
result.add(insertPosition + i, insertNumber + i);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public static int firstUniqChar(String s) {
2323
freq[s.charAt(i) - 'a']++;
2424
}
2525
for (int i = 0; i < s.length(); i++) {
26-
if (freq[s.charAt(i) - 'a'] == 1) return i;
26+
if (freq[s.charAt(i) - 'a'] == 1) {
27+
return i;
28+
}
2729
}
2830
return -1;
2931
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ public static int parse(String input) {
134134
int thisLen = 0;
135135
String[] paths = path.split("\\t");
136136
CommonUtils.printArray_generic_type(paths);
137-
if (paths[paths.length - 1].contains(".")) isFile = true;
137+
if (paths[paths.length - 1].contains(".")) {
138+
isFile = true;
139+
}
138140
if (isFile) {
139141
for (String eachDir : paths) {
140142
thisLen += eachDir.length();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public char findTheDifference(String s, String t) {
2929
}
3030
char result = 'a';
3131
for (int i = 0; i < 128; i++) {
32-
if (counts[i] != 0) result = (char) i;
32+
if (counts[i] != 0) {
33+
result = (char) i;
34+
}
3335
}
3436
return result;
3537
}

0 commit comments

Comments
 (0)