当前位置:网站首页>283.移动零
283.移动零
2022-07-01 03:28: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都是满足数组边界条件的
边栏推荐
- TEC: Knowledge Graph Embedding with Triple Context
- 小程序容器技术与物联网IoT的结合点
- Implement pow (x, n) function
- PageObject模式解析及案例
- IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does
- 242. 有效的字母异位词
- Test function in pychram
- [JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
- Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
- Asgnet paper and code interpretation 2
猜你喜欢

【TA-霜狼_may-《百人计划》】2.1 色彩空间

【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
![[TA frost wolf \u may- hundred people plan] 1.3 secret of texture](/img/dc/ce2819258632cdcf2e130a4c05600e.png)
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture

谷粒学院微信扫码登录过程记录以及bug解决

MFC窗口滚动条用法

Develop industrial Internet with the technical advantages of small programs

The programmer's girlfriend gave me a fatigue driving test

【TA-霜狼_may-《百人计划》】2.2 模型与材质空间

MFC window scroll bar usage

【TA-霜狼_may-《百人计划》】1.3纹理的秘密
随机推荐
389. 找不同
The combination of applet container technology and IOT
8. string conversion integer (ATOI)
程序员女友给我做了一个疲劳驾驶检测
[party benefits] jsonobject to string, leave blank
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
小程序容器技术与物联网IoT的结合点
Valentine's Day is nothing.
SEM of C language_ Tvariable type
在 C 中声明函数之前调用函数会发生什么?
72. 编辑距离
Asgnet paper and code interpretation 2
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
Use of JMeter counters
在线公网安备案保姆级教程【伸手党福利】
Binary tree god level traversal: Morris traversal
Network metering - application layer
【JPCS出版】2022年第三届控制理论与应用国际会议(ICoCTA 2022)
Feature Pyramid Networks for Object Detection论文理解