当前位置:网站首页>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
都是满足数组边界条件的
边栏推荐
- Explain spark operation mode in detail (local+standalone+yarn)
- [TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
- 72. 编辑距离
- The combination of applet container technology and IOT
- 431. 将 N 叉树编码为二叉树 DFS
- torch. histc
- PageObject模式解析及案例
- pytorch nn. AdaptiveAvgPool2d(1)
- How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
- 【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
猜你喜欢
Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
Millet College wechat scanning code login process record and bug resolution
Unexpected token o in JSON at position 1, JSON parsing problem
Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly
SEM of C language_ Tvariable type
LeetCode 128最长连续序列(哈希set)
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
Leetcode 128 longest continuous sequence (hash set)
随机推荐
Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
10、Scanner. Next() cannot read spaces /indexof -1
Complete knapsack problem
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture
Unexpected token o in JSON at position 1, JSON parsing problem
392. 判断子序列
431. 将 N 叉树编码为二叉树 DFS
187. repeated DNA sequences
214. minimum palindrome string
30. 串联所有单词的子串
The combination of applet container technology and IOT
318. 最大单词长度乘积
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation
FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
【TA-霜狼_may-《百人计划》】2.1 色彩空间
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page