标签:
题目描述:public class Solution { public void NextPermutation(int[] nums) { var index = -1; for(var i = nums.Length - 1; i > 0; i--){ if(nums[i] > nums[i-1]){ index = i-1; break; } } var index2 = -1; if(index != -1){ for(var i = nums.Length - 1; i >= 0; i--){ if(nums[i] > nums[index]){ index2 = i; break; } } } if(index != -1 && index2 != -1){ var t = nums[index]; nums[index] = nums[index2]; nums[index2] = t; } var k = index + 1; var j = nums.Length - 1; while(k < j){ var tmp = nums[k]; nums[k] = nums[j]; nums[j] = tmp; k++; j--; } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/48650053