当前位置:网站首页>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;
}
};
边栏推荐
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
- 网络相关知识(硬件工程师)
- Shenji Bailian 3.53-kruskal
- Verifying downloaded files using sha256 files
- 从设计交付到开发,轻松畅快高效率!
- 500. Keyboard line
- Flutter hybrid development: develop a simple quick start framework | developers say · dtalk
- Ros2 --- lifecycle node summary
- Fundamentals of software testing
- Step by step | help you easily submit Google play data security form
猜你喜欢

Introduce uview into uni app

Frequently asked questions about jetpack compose and material you

PHP development and testing WebService (soap) -win

Spark overview

深度学习分类网络 -- AlexNet

ES6的详细注解

Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')

How vite is compatible with lower version browsers

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

Let every developer use machine learning technology
随机推荐
JWT工具类
Reading classic literature -- Suma++
Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
Web page user step-by-step operation guide plug-in driver js
keepalived安装使用与快速入门
Software testing - concept
uni-app开发中遇到的问题(持续更新)
网络相关知识(硬件工程师)
JWT tool class
The official zero foundation introduction jetpack compose Chinese course is coming!
Stc8h8k series assembly and C51 actual combat - digital display ADC, key serial port reply key number and ADC value
Google Play Academy 组队 PK 赛,正式开赛!
Detailed steps of JS foreground parsing of complex JSON data "case: I"
Little bear sect manual query and ADC in-depth study
神机百炼3.54-染色法判定二分图
让每一位开发者皆可使用机器学习技术
Linkage between esp8266 and stc8h8k single chip microcomputer - Weather Clock
Picture clipping plug-in cropper js
Redis Key-Value数据库 【高级】
Stick to the big screen UI, finereport development diary