Skip to content

Next Permutation.py#109

Open
anandguptacv wants to merge 163 commits intoLancelot03-patch-1-2from
Lancelot03-patch-75
Open

Next Permutation.py#109
anandguptacv wants to merge 163 commits intoLancelot03-patch-1-2from
Lancelot03-patch-75

Conversation

@anandguptacv
Copy link
Contributor

class Solution(object):
def nextPermutation(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""

    i = j = len(nums)-1
    while i > 0 and nums[i]<=nums[i-1]:
        i-=1
    i-=1
    if i<0:
        nums.reverse()
        return
    
    while j>i and nums[j]<=nums[i]:
        j-=1
    
    nums[i],nums[j] = nums[j], nums[i]
    
    k,l = i+1, len(nums)-1
    
    while k<l:
        nums[k],nums[l] = nums[l], nums[k]
        k+=1
        l-=1

avinashthetech and others added 30 commits April 7, 2022 14:13
Create Find The Parity Outlier.py
Create Reducing Problems - Bug Fixing #8.py
Create A Chain adding function.py
Create A Chain adding function2.py
Create Find the smallest integer in the array.py
Create Formation of Linked list.py
Lancelot03 and others added 30 commits September 27, 2022 23:20
Update and rename py to Set Matrix Zero.cpp
Create Majority Elements 2.cpp
Create Count Reverse Pairs.cpp
Create Count the number of subarrays with given xor K.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants