当前位置:网站首页>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都是满足数组边界条件的
边栏推荐
- Error: plug ins declaring extensions or extension points must set the singleton directive to true
- MFC窗口滚动条用法
- [TA frost wolf \u may- hundred people plan] 1.3 secret of texture
- 166. 分数到小数
- 168. Excel表列名称
- 8. string conversion integer (ATOI)
- 389. 找不同
- 整合阿里云短信的问题:无法从静态上下文中引用非静态方法
- The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
- 208. implement trie (prefix tree)
猜你喜欢

Develop industrial Internet with the technical advantages of small programs

Network metering - application layer

The difference between MFC for static libraries and MFC for shared libraries
![[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算

MFC window scroll bar usage

Appium自动化测试基础--补充:C/S架构和B/S架构说明

RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs

Grid system in bootstrap

【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
随机推荐
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
Online public network security case nanny level tutorial [reaching out for Party welfare]
171. excel table column No
4. [WebGIS practice] software operation chapter - data import and processing
166. 分数到小数
Review column - message queue
Cygwin的下载和安装配置
Unexpected token o in JSON at position 1, JSON parsing problem
Error: plug ins declaring extensions or extension points must set the singleton directive to true
MFC窗口滚动条用法
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
Test function in pychram
【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
241. 为运算表达式设计优先级
205. isomorphic string
在线公网安备案保姆级教程【伸手党福利】
【JPCS出版】2022年第三届控制理论与应用国际会议(ICoCTA 2022)