283. Move Zeroes
来源:互联网 发布:知乎b站三国演义 编辑:程序博客网 时间:2024/06/10 22:05
Given an array nums
, write a function to move all 0
's to the end of it while maintaining the relative order of the non-zero elements.
For example, given nums = [0, 1, 0, 3, 12]
, after calling your function, nums
should be [1, 3, 12, 0, 0]
.
Note:
- You must do this in-place without making a copy of the array.
- Minimize the total number of operations.
public void moveZeroes(int[] nums) { int right = 0; //i是非零元素的index,j是零元素的index for(int left = 0; left < nums.length; left++) { //left先走,走到不是0元素的时候交换,交换完了right再走 if(nums[left] != 0) { int temp = nums[right]; nums[right] = nums[left]; nums[left] = temp; right++; } } }
0 0
- 283.Move Zeroes
- 283. Move Zeroes
- 283. Move Zeroes
- 283. Move Zeroes
- 283. Move Zeroes
- 【LeetCode】283. Move Zeroes
- 283. Move Zeroes
- 283. Move Zeroes
- Leetcode 283. Move Zeroes
- 283. Move Zeroes
- LeetCode #283. Move Zeroes
- 283. Move Zeroes LeetCode
- 283. Move Zeroes
- LeetCode 283. Move Zeroes
- LeetCode 283. Move Zeroes
- 283. Move Zeroes
- 283. Move Zeroes
- LeetCode 283. Move Zeroes
- summary
- dasdsad
- IOCP 服务端案例
- Install GPU Tensorflow
- 数据结构--队列
- 283. Move Zeroes
- Leetcode 210. Course Schedule II
- 关于P、NP问题和算法的一点联系
- #6. ZigZag Conversion
- 快速幂及其简单应用
- 1st round, 91 Decode Ways
- Java_每天学习一点点之基本结构
- Leetcode 131. Palindrome Partitioning
- 107. Binary Tree Level Order Traversal II