由买买提看人间百态

topics

全部话题 - 话题: endpos
(共0页)
s*i
发帖数: 5025
1
来自主题: JobHunting版 - FB 电面面经
The first one?
void placeZerosToEnd (int[] A)
{
if (A == null)
{
return;
}

int endPos = A.length - 1;
for (int i = 0; i < endPos; i++)
{
if (A[i] == 0)
{
A[i] = A[endPos];
A[endPos] = 0;
endPos --;
i--; //need to test this newly swapped element
}
}
}
s*i
发帖数: 5025
2
来自主题: JobHunting版 - FB 电面面经
The first one?
void placeZerosToEnd (int[] A)
{
if (A == null)
{
return;
}

int endPos = A.length - 1;
for (int i = 0; i < endPos; i++)
{
if (A[i] == 0)
{
A[i] = A[endPos];
A[endPos] = 0;
endPos --;
i--; //need to test this newly swapped element
}
}
}
(共0页)