【leetcode_medium】31. Next Permutation

leetcode_medium_array

problem

31. Next Permutation

solution #1: 

According to Wikipedia, a man named Narayana Pandita presented the following simple algorithm to solve this problem in the 14th century.

Find the largest index k such that nums[k] < nums[k + 1]. If no such index exists, just reverse nums and done.
Find the largest index l > k such that nums[k] < nums[l].
Swap nums[k] and nums[l].
Reverse the sub-array nums[k + 1:].

code

参考

1. leetcode_31. Next Permutation;

2. [高中生也能看懂的算法逻辑1] 下一个排列

做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
原文地址:https://www.cnblogs.com/happyamyhope/p/13331106.html