Why system judge my algorithm as a not in-place method, need help !!!!!!!!!!


  • 0
    S
    class Solution(object):
        def nextPermutation(self, nums):
            if not nums:
                return []
            if len(nums) == 1:
                return nums
                
            for i in xrange(len(nums)-2, -1, -1):
                if nums[i] >= nums[i+1]:
                    pass
                else:
                    for k in xrange(len(nums)-1, i,-1):
                        if nums[k] > nums[i]:
                            nums[k],nums[-1] = nums[-1],nums[k]
                            return nums[:i] + [nums[-1]] + nums[i:-1]
            return nums[::-1]

Log in to reply
 

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