Java | Leetcode Java题解之第283题移动零

avatar
作者
筋斗云
阅读量:0

题目:

题解:

class Solution {     public void moveZeroes(int[] nums) {         int n = nums.length, left = 0, right = 0;         while (right < n) {             if (nums[right] != 0) {                 swap(nums, left, right);                 left++;             }             right++;         }     }      public void swap(int[] nums, int left, int right) {         int temp = nums[left];         nums[left] = nums[right];         nums[right] = temp;     } }

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!