Why is my code get a result of RUNTIME ERROR?


  • 0
    G

    class Solution {

    void sortColors(vector<int>& nums) {
        vector<int>::iterator start=nums.begin();
        for(vector<int>::iterator temp=start;temp!=nums.end();temp++)
        {
            
            if(*temp==0)
             {nums.insert(nums.begin(),0);
             nums.erase(temp);
                 
             }
             if(*temp==2)
             {
                 nums.push_back(2);
                 nums.erase(temp);
             }
             
        }
    }

Log in to reply
 

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