We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
示例:
输入: [0,1,0,3,12] 输出: [1,3,12,0,0]
说明:
function moveZeroes(nums){ let count = 0; for(let i = 0, l = nums.length; i < l; i++){ if(nums[i] === 0){ count++; }else if(count > 0){ nums[i - count] = nums[i]; nums[i] = 0; } } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
示例:
说明:
解答
The text was updated successfully, but these errors were encountered: