当前位置:网站首页>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;
}
};
边栏推荐
- Sql Server之查询总结
- 104. Maximum depth of binary tree
- Sword finger offer (53): a string representing a numeric value
- Flutter jni混淆 引入.so文件release包闪退
- C language pengge 20210812c language function
- During the interview, how did the interviewer evaluate the level of rust engineers?
- 面试过程中,面试官是如何考察Rust工程师的水平?
- Newbie sees the source code arraydeque
- Wireshark basic tutorial Ethernet frame analysis.
- toolstrip 去边框
猜你喜欢

看源码之LinkedList

nmap弱点扫描结果可视化转换

Wireshark basic tutorial Ethernet frame analysis.

Disable usbjatg in Altium Designer

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

pytest 执行规则_基本用法_常用插件_常用断言_常用参数

ESXi6.5补丁更新

二叉树的遍历 递归+迭代

0x00007FFD977C04A8 (Qt5Sqld.dll)处(位于 a.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000010 时发生访问冲突

Sql Server 数据库之数据类型
随机推荐
[dectectron2] follow the official demo
Flutter 防止科学计数并去除尾数无效0
Flutter集成极光推送
shell 脚本 失败自动重复执行
Constructors, method overloads, object arrays, and static
Bash shell learning notes (4)
二叉树的遍历 递归+迭代
用两个栈实现队列
13 managing resources by objects
logging 高级使用
Bash shell学习笔记(六)
Newbie sees the source code arraydeque
pytest pytest.ini配置 用例分组 用例跳过
2021-08-12 function recursion_ Learn C language with brother Peng
很多人都不清楚自己找的是Kanban软件还是看板软件
MFC多线程的简单使用
104.二叉树的最大深度
菜鸟看源码之ArrayList
Sword finger offer (43): left rotation string
@NotBlank、@NotNull 、@NotEmpty 区别和使用