i**********e 发帖数: 1145 | 2 这个解法不对,有 bug.
test case:
{22,11,33,33,44,22,11}
t = 22,
output=
{11 33 33 44 44 22 22}
expected=
{11 33 33 44 11 22 22}
第一题的解:
void shiftArrayEqualsTBack(int num[], int n, int t) {
int total = 0;
for (int i = 0; i < n; i++) {
if (num[i] == t)
total++;
else
num[i-total] = num[i];
}
for (int i = n-total; i < n; i++) {
num[i] = t;
}
}
第二题的解:
const int X_MAX = 4;
const int Y_MAX = 4;
bool validLocation(int x, int y) {
if (x <= -1 || x >= X_MAX || y <= -1 || y >= Y... 阅读全帖 |
|