题目描述
解题代码
public class Solution2022 {
public int[][] construct2DArray(int[] original, int m, int n) {
if (original.length != m * n) {
return new int[0][0];
}
int[][] res = new int[m][n];
int index = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
res[i][j] = original[index];
index++;
}
}
return res;
}
}
解题结果
题目描述
这道题目,是2022年2月2日的每日一题
解题代码
public class Solution2000 {
public String reversePrefix(String word, char ch) {
int index = word.indexOf(ch);
if (index == -1) {
return word;
}
StringBuilder rev = new StringBuilder(word.substring(0, index + 1));
return rev.reverse().toString() + word.substring(index + 1);
}
}
解题结果