当前位置:网站首页>LeetCode 27. Removing Elements
LeetCode 27. Removing Elements
2022-07-02 06:10:00 【Great white sheep_ Aries】
Title Description
solution
Solution or speed pointer : If fast Encountered value is val The elements of , Then skip directly , Otherwise, it will be assigned to slow The pointer , And let slow Take a step forward
however , Notice here and the ordered array de duplication (26. Remove duplicate items from an ordered array ) There is one detail difference in the solution of , We are here to give nums[slow] Assign a value and then give it to slow++, This ensures nums[0…slow-1] Does not contain a value of val The elements of the , The final result is the length of the array slow
class Solution {
public:
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;
}
};
边栏推荐
- 495. Timo attack
- STC8H8K系列匯編和C51實戰——數碼管顯示ADC、按鍵串口回複按鍵號與ADC數值
- Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
- 492.构造矩形
- Google Play Academy 组队 PK 赛,正式开赛!
- 神机百炼3.54-染色法判定二分图
- 如何使用MITMPROXy
- Classic literature reading -- deformable Detr
- LeetCode 283. 移动零
- LeetCode 83. 删除排序链表中的重复元素
猜你喜欢

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

51单片机——ADC讲解(A/D转换、D/A转换)

51 single chip microcomputer - ADC explanation (a/d conversion, d/a conversion)

Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table

DRM display framework as I understand it

ROS2----LifecycleNode生命周期节点总结

Lucene Basics

Introduce uview into uni app

Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice

Deep learning classification network -- vggnet
随机推荐
AttributeError: ‘str‘ object has no attribute ‘decode‘
The real definition of open source software
External interrupts cannot be accessed. Just delete the code and restore it Record this unexpected bug
如何使用MITMPROXy
Generic classes and parameterized classes of SystemVerilog
让每一位开发者皆可使用机器学习技术
借力 Google Cloud 基础设施和着陆区,构建企业级云原生卓越运营能力
深度学习分类网络--VGGNet
Some experience of exercise and fitness
线性dp(拆分篇)
数据库学习总结5
cookie插件和localForage离线储存插件
页面打印插件print.js
VRRP之监视上行链路
I/o multiplexing & event driven yyds dry inventory
官方零基础入门 Jetpack Compose 的中文课程来啦!
神机百炼3.54-染色法判定二分图
Detailed steps of JS foreground parsing of complex JSON data "case: I"
Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
Google Play Academy 组队 PK 赛,正式开赛!