当前位置:网站首页>LeetCode 283. 移动零
LeetCode 283. 移动零
2022-07-02 06:07:00 【大白羊_Aries】
题目描述
解法
这道题其实就是 LeetCode 27. 移除元素 的延伸,将 0 全部删除然后再补上就好了
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int p = removeElement(nums, 0);
for (; p < nums.size(); p++)
nums[p] = 0;
}
int removeElement(vector<int>& nums, int val) {
if (nums.size() == 0) return 0;
int slow = 0, fast = 0;
while (fast < nums.size())
{
if (nums[fast] != val)
{
nums[slow] = nums[fast];
slow++;
}
fast++;
}
return slow;
}
};
边栏推荐
- [PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
- Regular expression summary
- Mathematical statistics and machine learning
- Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
- 神机百炼3.53-Kruskal
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
- 外部中断无法进入,删代码再还原就好......记录这个想不到的bug
- 【C语言】筛选法求素数
- Mock simulate the background return data with mockjs
- Some descriptions of Mipi protocol of LCD
猜你喜欢

Can't the dist packaged by vite be opened directly in the browser

500. 键盘行

keepalived安装使用与快速入门

在uni-app中引入uView

Deep learning classification network -- alexnet

脑与认知神经科学Matlab Psytoolbox认知科学实验设计——实验设计四

如何使用MITMPROXy

社区说|Kotlin Flow 的原理与设计哲学

浏览器原理思维导图

I/o impressions from readers | prize collection winners list
随机推荐
来自读者们的 I/O 观后感|有奖征集获奖名单
PHP inner class name is the same as the inner class method name
The real definition of open source software
Spark概述
AttributeError: ‘str‘ object has no attribute ‘decode‘
Community theory | kotlin flow's principle and design philosophy
Google play academy team PK competition, official start!
Current situation analysis of Devops and noops
Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
Servlet web XML configuration details (3.0)
外部中断无法进入,删代码再还原就好......记录这个想不到的bug
I/o impressions from readers | prize collection winners list
如何使用MITMPROXy
Redis Key-Value数据库 【秒杀】
ESP8266与STC8H8K单片机联动——天气时钟
JWT tool class
步骤详解 | 助您轻松提交 Google Play 数据安全表单
492.构造矩形
CNN visualization technology -- detailed explanation of cam & grad cam and concise implementation of pytorch