当前位置:网站首页>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;
}
};
边栏推荐
- Shenji Bailian 3.54-dichotomy of dyeing judgment
- 【C语言】简单实现扫雷游戏
- Redis key value database [advanced]
- Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
- No subject alternative DNS name matching updates. jenkins. IO found, the reason for the error and how to solve it
- Comment utiliser mitmproxy
- Summary of MySQL constraints
- Google play academy team PK competition, official start!
- 让每一位开发者皆可使用机器学习技术
- Nacos 启动报错 Error creating bean with name ‘instanceOperatorClientImpl‘ defined in URL
猜你喜欢
随机推荐
Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
Talking about MySQL database
深度学习分类网络--VGGNet
Nacos 启动报错 Error creating bean with name ‘instanceOperatorClientImpl‘ defined in URL
Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
495.提莫攻击
uni-app开发中遇到的问题(持续更新)
Ti millimeter wave radar learning (I)
MUI底部导航的样式修改
Deep learning classification network -- Network in network
PHP gets CPU usage, hard disk usage, and memory usage
步骤详解 | 助您轻松提交 Google Play 数据安全表单
神机百炼3.53-Kruskal
Some experience of exercise and fitness
Memcached installation
Software testing - concept
网络相关知识(硬件工程师)
I/o multiplexing & event driven yyds dry inventory
[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP
Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')