自从开始做 LeetCode 心里就住了几十个小人在哭每一个都是做不对或者做不出来痛哭流涕滚去扒别人代码留在我心里的。
然后这次直接题目都看不懂了……TAT
原题:
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
我的理解是:
找出用同样数字排列里,刚好比输入大的那一个。
但是我看讨论里面有个人说:
1243 应该变成 1342。
但是比 1243 大的还有 1324 啊??1324 还比 1342 小,为什么答案是 1342 而不是 1324?
同时这个人在讨论里也提到了,要把右半部分排一下序,1342不是很明显右边还没有排序吗?=。=
https://oj.leetcode.com/discuss/17631/share-my-python-code-and-explain-how-to-get-the-solution
我还在 github 上找了另一个答案,给的注释也是要
Find the largest l such that num[k] < num[l] (if k exists)
为什么不是
Find the smallest l but also required num[k] < num[l]
???
/痛哭流涕退下
然后这次直接题目都看不懂了……TAT
原题:
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
我的理解是:
找出用同样数字排列里,刚好比输入大的那一个。
但是我看讨论里面有个人说:
1243 应该变成 1342。
但是比 1243 大的还有 1324 啊??1324 还比 1342 小,为什么答案是 1342 而不是 1324?
同时这个人在讨论里也提到了,要把右半部分排一下序,1342不是很明显右边还没有排序吗?=。=
https://oj.leetcode.com/discuss/17631/share-my-python-code-and-explain-how-to-get-the-solution
我还在 github 上找了另一个答案,给的注释也是要
Find the largest l such that num[k] < num[l] (if k exists)
为什么不是
Find the smallest l but also required num[k] < num[l]
???
/痛哭流涕退下