Skip to content

Commit 3d659fd

Browse files
add a utils method
1 parent 44fb602 commit 3d659fd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/main/java/com/fishercoder/common/utils/CommonUtils.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,33 @@ public static void print2DCharArray(char[][] arrayArrays) {
253253
}
254254
System.out.println();
255255
}
256+
257+
public static int[][] convertLeetCodeArrayInputIntoJavaArray(String input) {
258+
String[] arrays = input.split("],\\[");
259+
// CommonUtils.printArray_generic_type(arrays);
260+
int size = arrays[1].split(",").length;
261+
int[][] output = new int[arrays.length][size];
262+
for (int i = 0; i < arrays.length; i++) {
263+
if (i == 0) {
264+
String str = arrays[i].substring(1);
265+
String[] nums = str.split(",");
266+
for (int j = 0; j < nums.length; j++) {
267+
output[i][j] = Integer.parseInt(nums[j]);
268+
}
269+
} else if (i == arrays.length - 1) {
270+
String str = arrays[i].substring(0, arrays[i].length() - 1);
271+
String[] nums = str.split(",");
272+
for (int j = 0; j < nums.length; j++) {
273+
output[i][j] = Integer.parseInt(nums[j]);
274+
}
275+
} else {
276+
String[] nums = arrays[i].split(",");
277+
for (int j = 0; j < nums.length; j++) {
278+
output[i][j] = Integer.parseInt(nums[j]);
279+
}
280+
}
281+
}
282+
// CommonUtils.print2DIntArray(output);
283+
return output;
284+
}
256285
}

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