当前位置:   article > 正文

C++ | Leetcode C++题解之第283题移动零

C++ | Leetcode C++题解之第283题移动零

题目:

题解:

  1. class Solution {
  2. public:
  3. void moveZeroes(vector<int>& nums) {
  4. int n = nums.size(), left = 0, right = 0;
  5. while (right < n) {
  6. if (nums[right]) {
  7. swap(nums[left], nums[right]);
  8. left++;
  9. }
  10. right++;
  11. }
  12. }
  13. };
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/901074
推荐阅读
相关标签
  

闽ICP备14008679号