8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 2ee4f1f + 1625e4a commit a99649dCopy full SHA for a99649d
algorithms/cpp/moveZeroes/moveZeroes.cpp
@@ -41,7 +41,7 @@ class Solution {
41
int i = 0, poz = 0;
42
for(i = 0; i < nums.size() && poz < nums.size(); i++)
43
{
44
- while(nums[poz] == 0)
+ while(poz < nums.size() && nums[poz] == 0)
45
poz++;
46
if(poz < nums.size())
47
nums[i] = nums[poz];
@@ -72,7 +72,7 @@ class Solution {
72
73
// Find the first ZERO, where is the tail of the array.
74
// (Notes: we can simply remove this!)
75
- for (; nums[p1]!=0 && p1<nums.size(); p1++);
+ for (; p1<nums.size() && nums[p1]!=0; p1++);
76
77
// copy the item from p2 to p1, and skip the ZERO
78
for (p2=p1; p2<nums.size(); p2++) {
0 commit comments