Leetcode 27 Remove Element STL

和remove zero类似的方法完成该题

 1 class Solution {
 2 public:
 3     int removeElement(vector<int>& nums, int val) {
 4         vector<int>::size_type j = 0;
 5         for(vector<int>::size_type i = 0; i < nums.size(); ++i){
 6             if(nums[i] != val) nums[j++] = nums[i];
 7         }
 8         return j;
 9     }
10 };

 

posted @ 2016-03-02 21:19  Breeze0806  阅读(119)  评论(0编辑  收藏  举报