Create 31. Next Permutation.md#55
Open
fuga-98 wants to merge 1 commit into
Open
Conversation
oda
reviewed
May 30, 2025
Comment on lines
+152
to
+156
| i = nums_length - 2 | ||
| while i >= 0: | ||
| if nums[i] < nums[i+1]: | ||
| break | ||
| i -= 1 |
There was a problem hiding this comment.
順序の入れ替え方の関数化などをしてもいいかなと思います。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.4qnnfvpo8ij5
Owner
Author
There was a problem hiding this comment.
Leetcode上だと短い関数は関数の定義を探す必要があるので、読みにくく感じて避けたのですが、
エディタ上なら分割したほうが読みやすそうです。
Comment on lines
+160
to
+162
| j = nums_length - 1 | ||
| while nums[j] <= nums[i]: | ||
| j -= 1 |
There was a problem hiding this comment.
これも名前をつけると、後ろから nums[i] 以上であるようなものを見つけるということですね。
nodchip
reviewed
May 31, 2025
| if nums[i] < nums[i + 1]: | ||
| break | ||
| i -= 1 | ||
| j = len(nums) - 1 |
There was a problem hiding this comment.
if 文の中で j を使っていないため、 j のスコープを短くするため、 if 文と j の定義を入れ替えたほうがよいと思います。
hroc135
reviewed
Jun 12, 2025
| ```python | ||
| class Solution: | ||
| def nextPermutation(self, nums: List[int]) -> None: | ||
| def reverse_in_range(lo, hi): |
There was a problem hiding this comment.
この関数は再利用する可能性がありそうなのでutilのようなモジュールに書くのも選択肢だと思いました。
Owner
Author
There was a problem hiding this comment.
確かに、これを書いているときにライブラリにないことに驚きました
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://leetcode.com/problems/next-permutation/description/