Create 0283-move-zeroes.md - #55
Open
naoto-iwase wants to merge 1 commit into
Open
Conversation
shintaro1993
reviewed
Nov 6, 2025
| return nothing, modify nums in-place instead. | ||
| """ | ||
| def swap(index1, index2): | ||
| nums[index1], nums[index2] = nums[index2], nums[index1] |
There was a problem hiding this comment.
自分はしませんでしたが、このように swap 処理を関数に切り出す方が for 文の中の見通しがよさそうだと感じました。好みかもしれませんが。
shintaro1993
reviewed
Nov 6, 2025
| swap_target_index = 0 | ||
| for i in range(len(nums)): | ||
| if nums[i] != 0: | ||
| swap(i, swap_target_index) |
There was a problem hiding this comment.
ただの感想になりますが、swap_target_index <= i なので swap(swap_target_index, i) と書くのも自然なのかなと少し思いました。ただどちらが自然なのか、それとも意識しなくてもいいのか、わかりませんでした。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。
自分もそこで迷いました。iが主役で、swap_target_indexが脇役のように感じたのでこの順序を採用しましたが、自分もどちらがより自然かわからなかったです。
shintaro1993
reviewed
Nov 6, 2025
| - [コメント集](https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.v62rdhwkdymb) | ||
| - https://discord.com/channels/1084280443945353267/1235829049511903273/1276579345099526267 | ||
| - > まとめて 0 fill は、loop unrolling できたりするのでちょっと嬉しいこともあるでしょう。 | ||
| - https://ja.wikipedia.org/wiki/%E3%83%AB%E3%83%BC%E3%83%97%E5%B1%95%E9%96%8B |
There was a problem hiding this comment.
キーワードからいろいろ調べられていて素晴らしいと思いました。自分は loop unrolling を初めて聞いたので調べてみようと思います。
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/move-zeroes/
次の問題:https://leetcode.com/problems/meeting-rooms/