Skip to content

Instantly share code, notes, and snippets.

@AkshayMathur92
AkshayMathur92 / Next Permutation.java
Created August 26, 2016 10:21 — forked from guolinaileen/Next Permutation.java
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replacement must be in-place, do not allocate extra memory. Here are some examples. Inputs are in the left…
public class Solution {
public void nextPermutation(int[] num) {
if(num.length==0) return;
int length=num.length;
int end=length-1;
int i=end-1;
for(; i>=0; i--)
{
if(num[i]>=num[i+1]) continue; //get an increasing set from the end
int j=end;