当前位置:网站首页>283.移动零
283.移动零
2022-06-24 09:47:00 【兀坐晴窗独饮茶】


主体思路 :
- 本质上和删除有序数组重复项类似, 都是满足 xxx 条件, 然后 执行 xxx 操作
- 删除有序数组重复项, 满足条件的直接覆盖即可, 因为是删除
- 而移动零, 并不是覆盖, 而是交换
- 所以 : 思路很简单 定义一个 count 用于记录零元素位置, 然后遍历元素, 当遇到非零元素就和零元素交换即可
细节问题 :
class Solution {
public void moveZeroes(int[] nums) {
int count = 0 ;
for (int i = 0 ; i < nums.length; i++) {
if (nums[i] != 0) {
int tmp = nums[count];
nums[count] = nums[i];
nums[i] = tmp;
count++;
}
}
}
}
- 本题中并无边界问题, 无论是
count还是i都是满足数组边界条件的
边栏推荐
- 3. addition, deletion, modification and query of employees
- 分布式系统你必须了解的点-CAP
- 2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
- Safety and food security for teachers and students of the trapped Yingxi middle school
- SQL Server AVG函数取整问题
- 百度网盘下载一直请求中问题解决
- How large and medium-sized enterprises build their own monitoring system
- 包装类型与基本类型的区别
- 【资源分享】2022年环境工程与生物技术国际会议(CoEEB 2022)
- Leetcode-498: diagonal traversal
猜你喜欢

5. dish management business development

How can I solve the problem that the swiper animation animation fails when switching between left and right rotations of the swiper?

Flink集群搭建以及企业级yarn集群搭建

6. package management business development

线程池的执行流程

正规方程、、、

抓包工具charles实践分享

【资源分享】2022年环境工程与生物技术国际会议(CoEEB 2022)

美国电子烟巨头 Juul 遭遇灭顶之灾,所有产品强制下架

SQL Server AVG函数取整问题
随机推荐
2.登陆退出功能开发
tf.errors
5.菜品管理业务开发
整理接口性能优化技巧,干掉慢代码
【资源分享】2022年环境工程与生物技术国际会议(CoEEB 2022)
Appium自动化测试基础 — 移动端测试环境搭建(一)
Juul, the American e-cigarette giant, suffered a disaster, and all products were forced off the shelves
1. project environment construction
uniapp开发微信小程序,显示地图功能,且点击后打开高德或腾讯地图。
Safety and food security for teachers and students of the trapped Yingxi middle school
【Energy Reports期刊发表】2022年能源与环境工程国际会议(CFEEE 2022)
2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
6.套餐管理业务开发
Six states of threads
机器学习——主成分分析(PCA)
上升的气泡canvas破碎动画js特效
Leetcode interview question 16.06: minimum difference
2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和。 n比较大,10的5次方。 来自美团。3.26笔试。
Record the range of data that MySQL update will lock
线程调度的常用方法