Skip to content

【Arai60】54問目 283. Move Zeroes#54

Merged
shining-ai merged 2 commits intomainfrom
review54
Jun 29, 2024
Merged

【Arai60】54問目 283. Move Zeroes#54
shining-ai merged 2 commits intomainfrom
review54

Conversation

@shining-ai
Copy link
Copy Markdown
Owner

"""
Do not return anything, modify nums in-place instead.
"""
num_zero = 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

個人的には num_zeros と zero を複数形にしたいです。

for i in range(len(nums)):
if nums[i] == 0:
continue
nums[last_fixed_index + 1], nums[i] = nums[i], nums[last_fixed_index + 1]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スワップせず、 nums[last_fixed_index + 1] = nums[i] とし、残った部分を 0 で埋めても良いと思います。

last_fixed_index = 0 から始めると、 + 1 が不要になると思います。この場合、変数名を変えるとよいと思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変数名をnon_zeros_lengthとしてみました。
swapだと残りの部分が0になっていることを少し考えないといけない気がしたので、最後に0埋めする方が読みやすいと思いました。

Copy link
Copy Markdown

@nodchip nodchip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よいと思います。

@shining-ai shining-ai merged commit b9fca55 into main Jun 29, 2024
@shining-ai shining-ai deleted the review54 branch June 29, 2024 14:08
@rihib rihib mentioned this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants