当前位置:网站首页>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都是满足数组边界条件的
边栏推荐
- [shortcut key]
- [party benefits] jsonobject to string, leave blank
- [EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
- [EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
- Binary tree god level traversal: Morris traversal
- Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
- 谷粒学院微信扫码登录过程记录以及bug解决
- 【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎
- Pyramid scene parsing network [pspnet] thesis reading
- Leetcode:829. Sum of continuous integers
猜你喜欢

Millet College wechat scanning code login process record and bug resolution

TEC: Knowledge Graph Embedding with Triple Context

The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
![[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis](/img/94/99090ea91082a385968e071ef3766c.png)
[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis
![[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation](/img/49/173b1f1f379faa28c503165a300ce0.png)
[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation

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

[TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API

Idea plug-in backup table

FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
![5. [WebGIS practice] software operation - service release and permission management](/img/5d/070e207bd96e60ba1846d644d4fb54.png)
5. [WebGIS practice] software operation - service release and permission management
随机推荐
用小程序的技术优势发展产业互联网
10. regular expression matching
[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation
409. longest palindrome
PageObject模式解析及案例
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
Binary tree god level traversal: Morris traversal
Usage of AfxMessageBox and MessageBox
LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
392. 判断子序列
168. Excel表列名称
Implement pow (x, n) function
Database DDL (data definition language) knowledge points
The difference between MFC for static libraries and MFC for shared libraries
MFC窗口滚动条用法
Feature pyramid networks for object detection
Idea plug-in backup table
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation
Grid system in bootstrap
[EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)