LeetCode - 27. Remove Element
2016-02-19 16:44
288 查看
27. Remove Element
Problem's Link
----------------------------------------------------------------------------[b]Mean:[/b]
移除数组中的指定元素.
[b]analyse:[/b]
略
[b]Time complexity: O(N)[/b]
[b]view code[/b]
/**
* -----------------------------------------------------------------
* Copyright (c) 2016 crazyacking.All rights reserved.
* -----------------------------------------------------------------
* Author: crazyacking
* Date : 2016-02-19-16.20
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long(LL);
typedef unsigned long long(ULL);
const double eps(1e-8);
class Solution
{
public:
int removeElement(vector<int>& nums, int val)
{
int cnt=0;
for(int i=0;i<nums.size();++i)
if(nums[i]==val)
++cnt;
else
nums[i-cnt]=nums[i];
return (nums.size()-cnt);
}
};
int main()
{
Solution solution;
int n,val;
while(cin>>n>>val)
{
vector<int> ve;
for(int i=0;i<n;++i)
{
int tmp;
cin>>tmp;
ve.push_back(tmp);
}
cout<<solution.removeElement(ve,val)<<endl;
}
return 0;
}
/*
*/
相关文章推荐
- IoGetCurrentIrpStackLocation和IoSkipCurrentIrpStackLocation和IoCopyCurrentIrpStackLocationToNext
- ]postgresql 维护手册
- Python编辑器UliPad安装
- join和on语句中select语句选择公共列的区别
- PHP create_function()代码注入
- oc与js交互
- 使用异或进行简单的密码加密(JAVA实现)
- 安全驾驶-试驾(五十四)
- leetcode笔记--Reverse Nodes in k-Group
- 算法题24 二叉树的中序遍历之二叉搜索树转排序双向链表
- 使用Eclipse构建Maven项目
- 数据流中的中位数
- Linux启动流程图解
- 对table元素相关的标签和属性一点总结
- 工厂方法模式
- Extjs实现文件上传
- Sublime Text 3103激活码
- Unity dll 热更新 基础框架
- 安全驾驶-玻璃水 (五十三)
- 《算法竞赛入门经典》(第二版)学习报告