Code running for [1,2] as custom testcase but shows runtime error with [1,2] when I submit?


  • 0
    A

    Code:

    class Solution {
    public:
        void nextPermutation(vector<int>& nums) {
            for(i=nums.size()-2;i>=0;i--)
            {
                if(nums[i]<nums[i+1]) break;
            }
            int minind=i+1,j;
           for(j=i+1;j<nums.size();j++)
           {
               if(nums[j]>nums[i] && nums[j]<=nums[minind]) minind = j;
           }
           int tmp=nums[minind]; nums[minind]=nums[i];nums[i]=tmp;
           sort(nums.begin()+i+1,nums.end());
          }
    };

Log in to reply
 

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