|
1 | 1 | package com_github_leetcode; |
2 | 2 |
|
3 | | -import java.util.ArrayList; |
4 | | -import java.util.Collections; |
5 | 3 | import java.util.List; |
6 | 4 |
|
7 | 5 | public class CommonUtils { |
@@ -54,40 +52,6 @@ public static boolean compareMatrix(List<List<Integer>> mt1, List<List<Integer>> |
54 | 52 | return true; |
55 | 53 | } |
56 | 54 |
|
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 | | - |
91 | 55 | public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(String input) { |
92 | 56 | /* |
93 | 57 | * LeetCode 2-d array input usually comes like this: it's a REGULAR rectangle |
@@ -173,62 +137,4 @@ public static int[][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(S |
173 | 137 | } |
174 | 138 | return output; |
175 | 139 | } |
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 | | - } |
234 | 140 | } |
0 commit comments