Leetcode Remove Element解题报告

来源:互联网 发布:csgo弹道优化参数脚本 编辑:程序博客网 时间:2024/05/22 15:04

这道题跟上一篇remove duplicates from sorted array的解法是一样的,只是判断条件不一样。。。


class Solution {public:    int removeElement(vector<int>& nums, int val) {        int len = nums.size();        if(len==0)            return 0;        int pos = 0;        for(int i = 0;i<len;i++)        {            if(nums[i]!=val)                nums[pos++] = nums[i];        }        return pos;    }};

原创粉丝点击