2.1.11 —线性表—Remove Element
来源:互联网 发布:查询进口商品数据 编辑:程序博客网 时间:2024/06/03 16:33
描述
Given an array and a value, remove all instances of that value in place and return the new length.
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn’t matter what you leave beyond the new length.
#include<iostream>using namespace std;int RemoveElement(int a[], int n,int value){if (a == NULL || n <= 0)return 0;int i = 0;int k = 0;for (; i < n; ){if (a[i] == value){i++;}else{a[k] = a[i];k++;i++;}}return k;}int main(){const int n = 10;int a[n] = { 1, 2, 4, 4, 4, 4, 5, 6, 6, 6 };int value = 6;int k = RemoveElement(a, n, value);for (int i = 0; i < k; i++)cout << a[i] << " ";cout << endl;}
阅读全文
0 0
- 2.1.11 —线性表—Remove Element
- Leetcode 线性表 Remove Element
- 2.1.11 Remove Element
- LeetCode——Remove Element
- LeetCode——Remove Element
- LeetCode——Remove Element
- LeetCode27——Remove Element
- Leetcode——remove-element
- <27>——Remove Element
- Algorithms—27.Remove Element
- Python学习——leetcode(Remove Element)
- Remove Element ——结题报告
- leetcode 027 —— Remove Element
- LeetCode题解——Remove Element
- Leetcode——27. Remove Element
- 算法系列—— Remove Element
- 27. Remove Element —— Java
- 11:Remove Element
- Weex与Android擦出的那些火花之 快速上手
- Java 体系结构介绍
- JNI中参数的传递与操作(中)
- 翻转(reverse)字符串(string)的所有方法 详解
- QWidget 页面刷新慢
- 2.1.11 —线性表—Remove Element
- js异步编程原理
- 解决ArcGIS-OpenStreetMap Toolbox-Load OSM File错误
- NotFoundError:Tensor name "incept5b_1/..." not found in checkpoint files /home/cqh2/...
- android加入谷歌地图(1)
- 98. Validate Binary Search Tree
- 利用百度贴吧上首页
- 牛客网刷题笔记--链表
- android 后台发送邮件到指定邮箱