MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / nextPermutation

Method nextPermutation

NextPermutation.java:3–15  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

1class Solution
2{
3 public void nextPermutation(int[] nums)
4 {
5 int i=nums.length-2;
6 int j=0;
7 while(i>=0 && nums[i]>=nums[i+1]) i--;
8 if(i>=0)
9 {
10 j=nums.length-1;
11 while(nums[j]<=nums[i]) j--;
12 swap(nums,i,j);
13 }
14 reverse(nums,i+1,nums.length-1);
15 }
16
17 public static void swap(int nums[],int i,int j)
18 {

Callers

nothing calls this directly

Calls 2

swapMethod · 0.95
reverseMethod · 0.95

Tested by

no test coverage detected