Skip to content

Commit 881e6f7

Browse files
authored
Resolved Idea warnings
1 parent 8cbc11d commit 881e6f7

File tree

4 files changed

+3
-96
lines changed

4 files changed

+3
-96
lines changed

src/main/java/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public int countCombinations(String[] pieces, int[][] positions) {
5555
return dfs(positions, endPosition, new int[pieces.length], 0);
5656
}
5757

58-
private int dfs(int[][] positions, ArrayList[] stop, int[] stopIndex, int cur) {
58+
private int dfs(int[][] positions, ArrayList<int[]>[] stop, int[] stopIndex, int cur) {
5959
if (cur == stopIndex.length) {
6060
int[][] p = new int[positions.length][2];
6161
for (int i = 0; i < p.length; i++) {

src/main/java/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public long countPairs(int n, int[][] edges) {
1515
long ans = 0;
1616
for (int i = 0; i < n; i++) {
1717
int p = d.findParent(i);
18-
int cnt = map.containsKey(p) ? map.get(p) : 0;
18+
int cnt = map.getOrDefault(p, 0);
1919
ans += i - cnt;
2020
map.put(p, map.getOrDefault(p, 0) + 1);
2121
}

src/test/java/com_github_leetcode/CommonUtils.java

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com_github_leetcode;
22

3-
import java.util.ArrayList;
4-
import java.util.Collections;
53
import java.util.List;
64

75
public class CommonUtils {
@@ -54,40 +52,6 @@ public static boolean compareMatrix(List<List<Integer>> mt1, List<List<Integer>>
5452
return true;
5553
}
5654

57-
public static char[][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray(String input) {
58-
/*
59-
* LeetCode 2-d char array usually comes in like this:
60-
* ["#"," ","#"],[" "," ","#"],["#","c"," "] which is wrapped in double quotes instead
61-
* of single quotes which makes it not usable in Java code.
62-
* This method helps with the conversion.
63-
*/
64-
String[] arrays = input.split("],\\[");
65-
int m = arrays.length;
66-
int n = arrays[1].split(",").length;
67-
char[][] ans = new char[m][n];
68-
for (int i = 0; i < m; i++) {
69-
if (i == 0) {
70-
String str = arrays[i].substring(1);
71-
String[] strs = str.split(",");
72-
for (int j = 0; j < strs.length; j++) {
73-
ans[i][j] = strs[j].charAt(1);
74-
}
75-
} else if (i == m - 1) {
76-
String str = arrays[i].substring(0, arrays[i].length() - 1);
77-
String[] strs = str.split(",");
78-
for (int j = 0; j < strs.length; j++) {
79-
ans[i][j] = strs[j].charAt(1);
80-
}
81-
} else {
82-
String[] strs = arrays[i].split(",");
83-
for (int j = 0; j < strs.length; j++) {
84-
ans[i][j] = strs[j].charAt(1);
85-
}
86-
}
87-
}
88-
return ans;
89-
}
90-
9155
public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(String input) {
9256
/*
9357
* LeetCode 2-d array input usually comes like this: it's a REGULAR rectangle
@@ -173,62 +137,4 @@ public static int[][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(S
173137
}
174138
return output;
175139
}
176-
177-
public static List<List<String>> convertLeetCode2DStringArrayInputIntoJavaArray(String input) {
178-
/*
179-
* How to copy LeetCode 2-d String array into this method:
180-
* 1. remove the beginning and ending quotes;
181-
* 2. put double quotes into this method parameter;
182-
* 3. copy the input into the double quotes.
183-
*
184-
* LeetCode 2-d array input usually comes like this: each row could have different length
185-
* [["A","B"],["C"],["B","C"],["D"]]
186-
* The expected input for this method is: "[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]"
187-
* just copy the LeetCode input: ["A","B"],["C"],["B","C"],["D"] into double quotes in Java,
188-
* it'll auto escape the double quotes.
189-
* i.e. strip off the beginning and ending square brackets, that's it.
190-
* The output of this method will be a standard Java 2-d array.
191-
* */
192-
String[] arrays = input.split("],\\[");
193-
List<List<String>> result = new ArrayList<>();
194-
for (int i = 0; i < arrays.length; i++) {
195-
List<String> level = new ArrayList<>();
196-
String[] strings;
197-
if (i == 0) {
198-
strings = arrays[i].substring(1).split(",");
199-
} else if (i == arrays.length - 1) {
200-
strings = arrays[i].substring(0, arrays[i].length() - 1).split(",");
201-
} else {
202-
strings = arrays[i].split(",");
203-
}
204-
Collections.addAll(level, strings);
205-
result.add(level);
206-
}
207-
return result;
208-
}
209-
210-
public static List<String> convertLeetCode1DStringArrayInputIntoJavaArray(String input) {
211-
/*
212-
* LeetCode 2-d array input usually comes like this: each row could have different length
213-
* ["A","B","C"]
214-
* The expected input for this method is: "[\"A\",\"B\",\"C\"]"
215-
* just copy the LeetCode input: ["A","B","C"] into double quotes in Java,
216-
* it'll auto escape the double quotes.
217-
* The output of this method will be a standard Java 1-d array.
218-
* */
219-
String[] arrays = input.split(",");
220-
List<String> result = new ArrayList<>();
221-
for (int i = 0; i < arrays.length; i++) {
222-
String word;
223-
if (i == 0) {
224-
word = arrays[i].substring(1);
225-
} else if (i == arrays.length - 1) {
226-
word = arrays[i].substring(0, arrays[i].length() - 1);
227-
} else {
228-
word = arrays[i];
229-
}
230-
result.add(word);
231-
}
232-
return result;
233-
}
234140
}

src/test/java/g0001_0100/s0096_unique_binary_search_trees/SolutionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void numTrees() {
1111
assertThat(new Solution().numTrees(3), equalTo(5));
1212
}
1313

14+
@Test
1415
void numTrees2() {
1516
assertThat(new Solution().numTrees(1), equalTo(1));
1617
}

0 commit comments

Comments
 (0)