C++ works for "run code" but have run time error in submitting...


  • 0
    H
    class Solution {
    public:
        int removeElement(vector<int>& nums, int val) {
            
           int n=nums.size();
            int end=n;
            
            for(int i=0;i<end;i++)
            {
                
                if(nums[i]==val)
                {
                    while(nums[end-1]==val){end--;}
                    swap(nums[i],nums[end-1]);
                    end--;
                }
               
                
            }
            
            return end;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.