当前位置:网站首页>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都是满足数组边界条件的
边栏推荐
- web网站开发,图片懒加载
- How large and medium-sized enterprises build their own monitoring system
- Caching mechanism for wrapper types
- Sort out interface performance optimization skills and kill slow code
- Leetcode interview question 01.05: primary editing
- 小程序 rich-text中图片点击放大与自适应大小问题
- 【IEEE出版】2022年服务机器人国际研讨会(IWoSR 2022)
- np.float32()
- Younger sister Juan takes you to learn JDBC --- 2-day sprint Day1
- 时尚的弹出模态登录注册窗口
猜你喜欢

Uniapp develops a wechat applet to display the map function, and click it to open Gaode or Tencent map.

canvas无限扫描js特效代码

线程的 sleep() 方法与 wait() 方法的区别

Resolved: methods with the same name as their class will not be constructors in

记录一下MySql update会锁定哪些范围的数据

p5.js实现的炫酷交互式动画js特效

5. dish management business development

4.分类管理业务开发

JMeter接口测试工具基础— 使用Badboy录制JMeter脚本

SQL Server AVG函数取整问题
随机推荐
微信小程序rich-text图片宽高自适应的方法介绍(rich-text富文本)
numpy.logical_or
The difference between static link library and dynamic link library
SSM整合
np. float32()
Baidu online disk download has been in the process of requesting solutions
numpy. linspace()
2.登陆退出功能开发
整理接口性能优化技巧,干掉慢代码
线程池的状态
Uniapp develops wechat official account, and the drop-down box selects the first one in the list by default
uniapp实现点击拨打电话功能
Leetcode-929: unique email address
用扫描的方法分发书稿校样
Leetcode-2221: triangular sum of arrays
线程的六种状态
tf. errors
【IEEE出版】2022年智能交通与未来出行国际会议(CSTFM 2022)
【IEEE出版】2022年服务机器人国际研讨会(IWoSR 2022)
2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和。 n比较大,10的5次方。 来自美团。3.26笔试。