当前位置:网站首页>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;
}
};
边栏推荐
- Software testing - concept
- Flutter hybrid development: develop a simple quick start framework | developers say · dtalk
- Several keywords in C language
- Redis key value database [primary]
- Stc8h8k series assembly and C51 actual combat - digital display ADC, key serial port reply key number and ADC value
- Verifying downloaded files using sha256 files
- CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现
- On Web server
- The official zero foundation introduction jetpack compose Chinese course is coming!
- Web page user step-by-step operation guide plug-in driver js
猜你喜欢

Classic literature reading -- deformable Detr

在uni-app中引入uView

Flutter hybrid development: develop a simple quick start framework | developers say · dtalk

DRM display framework as I understand it

I/o impressions from readers | prize collection winners list

AttributeError: ‘str‘ object has no attribute ‘decode‘

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

memcached安装

网络相关知识(硬件工程师)

步骤详解 | 助您轻松提交 Google Play 数据安全表单
随机推荐
Stick to the big screen UI, finereport development diary
Lambda expressions and method references
Ti millimeter wave radar learning (I)
PHP inner class name is the same as the inner class method name
来自读者们的 I/O 观后感|有奖征集获奖名单
ZABBIX server trap command injection vulnerability (cve-2017-2824)
让每一位开发者皆可使用机器学习技术
TI毫米波雷达学习(一)
servlet的web.xml配置详解(3.0)
【C语言】筛选法求素数
Style modification of Mui bottom navigation
How vite is compatible with lower version browsers
STC8H8K系列汇编和C51实战——数码管显示ADC、按键串口回复按键号与ADC数值
Shenji Bailian 3.54-dichotomy of dyeing judgment
Detailed steps of JS foreground parsing of complex JSON data "case: I"
Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
Redis key value database [primary]
Format check JS
Spark概述
网络相关知识(硬件工程师)