当前位置:网站首页>2.1-----27. Remove elements
2.1-----27. Remove elements
2022-08-09 02:05:00 【@ Bai Gui】
一、题目


二、代码
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
//Variables are used routinely
int i=0;
int count_num_sub=0; //用于记录数组的长度
int return_count=0;
//variables in this question
int size= nums.size();
if(size!=0)
{
int another_num[size];
for(i=0;i<=size-1;i++) another_num[i]=0; //The array is declared and cleared
for(i=0;i<=size-1;i++) //依次查找 If not removed into another array
{
if(nums[i]!=val)
{
std::cout<<" i "<< i<<std::endl;
another_num[count_num_sub]=nums[i];
count_num_sub=count_num_sub+1;
}
}
return_count=count_num_sub;
//At this point the final numbers and arrays have been obtained reverse coverage
for(i=0;i<=size-1;i++) nums[i]=another_num[i]; //The array is declared and cleared
}
else return_count=0;
return return_count;
}
};
三、运行结果

边栏推荐
猜你喜欢

力扣刷题记录4.1-----209. 长度最小的子数组

How SEMRush finds keywords for advertising

LeetCode每日两题01:二分查找 (均1200道)

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules

Etcd realize large-scale application service management of actual combat

力扣刷题记录2.1-----27. 移除元素

考研人总结的时间管理7大忌,你中了几条?

2022 PMP Project Management Certification Exam Registration Guide (1)

New Swagger3.0 tutorial, OAS3 quick configuration guide, to automate API interface documentation!

HCIP-R&S By Wakin自用笔记(2)OSPF之OSPF回顾、虚连接
随机推荐
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
How to install yii2
[C language brush questions] Application of fast and slow pointers in linked lists
2022护眼产品展,北京眼健康展,眼科医学展,近视矫正设备展
LeetCode每日两题01:二分查找 (均1200道)
LeetCode每日两题01:有序数组的平方 (均1200道)方法:双指针
Significance Test--Study Notes
力扣刷题记录4.1-----209. 长度最小的子数组
Observer pattern
UsernameAuthenticationFilter授权成功后调用AuthenticationSuccessHandler时的解析
js实现数组去重的方式(7种)
2022杭电多校第五场1007(生成函数+启发式合并+ntt)
力扣刷题记录2.1-----27. 移除元素
虹科技术|如何阻止供应链攻击?
如何在推荐系统中玩转知识图谱
如何在EasyDSS中使用ffmpeg实现点播视频的拼接与合成?
数据恢复软件EasyRecovery支持恢复所有类型的文件
pytorch相关知识点总结
Docker redis master-slave replication setup, the container cannot be started?
Go-11-流程控制