当前位置:网站首页>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;
}
};
边栏推荐
- JWT tool class
- Current situation analysis of Devops and noops
- Redis Key-Value数据库 【秒杀】
- Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
- Let every developer use machine learning technology
- External interrupts cannot be accessed. Just delete the code and restore it Record this unexpected bug
- Addchild() and addattribute() functions in PHP
- ESP8266与STC8H8K单片机联动——天气时钟
- 让每一位开发者皆可使用机器学习技术
- Shenji Bailian 3.54-dichotomy of dyeing judgment
猜你喜欢

Frequently asked questions about jetpack compose and material you

Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability

ESP8266与STC8H8K单片机联动——天气时钟

Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
![[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法](/img/25/73f11ab2711ed2cc9f20bc7f9116b6.png)
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法

Keepalived installation, use and quick start

Deep learning classification network -- alexnet

Test case

线性dp(拆分篇)

Can't the dist packaged by vite be opened directly in the browser
随机推荐
Problems encountered in uni app development (continuous update)
Reading classic literature -- Suma++
经典文献阅读之--Deformable DETR
PHP inner class name is the same as the inner class method name
MUI底部导航的样式修改
Community theory | kotlin flow's principle and design philosophy
CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现
Shenji Bailian 3.54-dichotomy of dyeing judgment
Current situation analysis of Devops and noops
外部中断无法进入,删代码再还原就好......记录这个想不到的bug
Format check JS
Google Play Academy 组队 PK 赛,正式开赛!
Redis key value database [advanced]
Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')
ROS2----LifecycleNode生命周期节点总结
Step by step | help you easily submit Google play data security form
Go 学习笔记整合
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
memcached安装
Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music