leetcode第一刷_Remove Element
来源:互联网 发布:c语言制表符是什么 编辑:程序博客网 时间:2024/06/16 16:27
水题。
这道题的题干直接把思路说出来了啊。。惊呆了。
两个指针,一前一后,遇到要去掉的数字就把后面的换上来,呵呵。
inline void swap(int &a, int &b){ int tp = a; a = b; b = tp;}class Solution {public: int removeElement(int A[], int n, int elem) { if(A == 0) return 0; int end = n-1; while(A[end--] == elem); for(int i=0;i<end;i++){ if(A[i] == elem){ swap(A[i], A[end]); while(A[--end] == elem); } } return end+1; }};
0 0
- leetcode第一刷_Remove Element
- LeetCode 27_Remove Element
- leetcode第一刷_Remove Duplicates from Sorted List II
- leetcode第一刷_Remove Duplicates from Sorted Array II
- leetcode 第一刷_Remove Nth Node From End of List
- 0027_Remove Element
- LeetCode 26_Remove Duplicates from Sorted Array
- 刷leetcode:Majority Element
- LeetCode 19_Remove Nth Node From End of List
- 刷leetcode:Find Peak Element
- leetcode第一刷_Candy
- leetcode第一刷_Triangle
- leetcode第一刷_Combinations
- leetcode第一刷_Anagrams
- leetcode第一刷_Permutations
- leetcode第一刷_Triangle
- leetcode第一刷_3Sum
- leetcode第一刷_4Sum
- asdfdsaf
- 在EL中调用静态函数
- 小米论坛用户数据遭泄漏
- install MEAN(MongoDB,Expressjs,Angularjs,Nodejs)
- 调试的一些技巧
- leetcode第一刷_Remove Element
- 1、免账号访问Windows共享文件
- Android-自定义PopupWindow
- 取数组中和最大的一段连续序列
- 我们为什么会喜欢《美国末日》中的Ellie
- c#中单例的实现
- UVA11889 Benefit
- ubuntu 13.10搭建MTK android源码编译环境
- leetcode第一刷_Populating Next Right Pointers in Each Node II