Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next Permutation.py #109

Open
wants to merge 163 commits into
base: Lancelot03-patch-1-2
Choose a base branch
from
Open

Conversation

DevilANANDGupta
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