当前位置:网站首页>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;
}
};
边栏推荐
- Data playback partner rviz+plotjuggler
- Memcached installation
- On Web server
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music
- 数据库学习总结5
- Redis Key-Value数据库 【高级】
- PHP gets CPU usage, hard disk usage, and memory usage
- Classic literature reading -- deformable Detr
- PHP extensions
- mock-用mockjs模拟后台返回数据
猜你喜欢
Test case
MySQL transaction and isolation level
Deep learning classification network -- Network in network
Classic literature reading -- deformable Detr
穀歌出海創業加速器報名倒計時 3 天,創業人闖關指南提前收藏!
让每一位开发者皆可使用机器学习技术
Deep learning classification network -- vggnet
ROS2----LifecycleNode生命周期节点总结
深度学习分类网络--Network in Network
浏览器原理思维导图
随机推荐
图片裁剪插件cropper.js
Lambda 表达式 和 方法引用
从设计交付到开发,轻松畅快高效率!
Google Play Academy 组队 PK 赛,正式开赛!
[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP
Page printing plug-in print js
Picture clipping plug-in cropper js
How to use mitmproxy
JWT tool class
Ros2 --- lifecycle node summary
线性dp(拆分篇)
Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
keepalived安装使用与快速入门
cookie插件和localForage离线储存插件
Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
token过期自动续费方案和实现
【C语言】筛选法求素数
PHP inner class name is the same as the inner class method name
Stc8h8k series assembly and C51 actual combat - keys allow key counting (using falling edge interrupt control)
Detailed steps of JS foreground parsing of complex JSON data "case: I"