当前位置:网站首页>27. Remove elements
27. Remove elements
2022-07-26 10:53:00 【Forest_ one thousand and ten】
Title Description :
Give you an array nums And a value val, You need In situ Remove all values equal to val The elements of , And return the new length of the array after removal .
Don't use extra array space , You have to use only O(1) Additional space and In situ Modify input array .
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
// Use two subscripts , Traverse array first
// If it is not the target value , Just cover the element forward to the array , It is equivalent to deleting the element
// Returns the subscript
int index = 0;
for (int i = 0; i < nums.size(); ++i)
{
if (val != nums[i])
{
nums[index++] = nums[i];
}
}
return index;
}
};
边栏推荐
- Pengge C language sixth class
- Analysis of C # delegation and anonymous method
- 菜鸟看源码之LinkedBlockingQueue
- 智能合约dapp系统开发流程技术
- Minesweeping Pro version 2021-08-19
- Common classes (understand)
- 解决org.apache.commons.codec.binary.Base64爆红问题
- Error[pe147]: declaration is incompatible with 'error problem
- flutter dart生成N个区间范围内不重复随机数List
- MySQL quicklearn-2021-09-01
猜你喜欢

@Notblank, @notnull, @notempty differences and uses

pytest conftest.py和fixture的配合使用
![[dectectron2] follow the official demo](/img/aa/03e46897234c309415b336ac39b7d9.png)
[dectectron2] follow the official demo

The problem of formatting IAR sprintf floating point to 0.0 in UCOS assembly

Bash shell学习笔记(一)

SCADA和三大工业控制系统PLC、DCS、FCS

Bash shell learning notes (I)

如何组装一个注册中心?

RT thread learning notes (I) -- configure RT thread development environment

Drbl diskless startup + Clonezilla network backup and restore system
随机推荐
Esxi6.5 patch update
Sword finger offer (43): left rotation string
c 语言中宏参数的字符串化跟宏参数的连接
How to assemble a registry?
MFC多线程的简单使用
Sql Server 之SQL语句对基本表及其中的数据的创建和修改
Sword finger offer (52): regularization expression
解决org.apache.commons.codec.binary.Base64爆红问题
@NotBlank、@NotNull 、@NotEmpty 区别和使用
Bigdecimal的加减乘除、比较大小、向上向下取整 和 Bigdecimal的集合累加、判断BigDecimal是否有小数
pytest conftest.py和fixture的配合使用
pytest 用例执行顺序
During the interview, how did the interviewer evaluate the level of rust engineers?
Error[pe147]: declaration is incompatible with 'error problem
Flutter jni混淆 引入.so文件release包闪退
13 managing resources by objects
232. Implement queue with stack
BigDecimal's addition, subtraction, multiplication and division, size comparison, rounding up and down, and BigDecimal's set accumulation, judge whether BigDecimal has decimal
Flutter集成极光推送
Bash shell学习笔记(四)