Skip to content

Conversation

@Satorien
Copy link
Owner

Comment on lines +61 to +64
index = 0
zero_count = 0
nums_len = len(nums)
while index + zero_count < nums_len:

Choose a reason for hiding this comment

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

indexをnon_zero_countと命名するとループ継続条件がより明快になりそうです。

あるいは、indexは必ずindex + zero_countの形でしか使わないのでこれをindexやiとする方が自然に感じます。

Copy link
Owner Author

Choose a reason for hiding this comment

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

その書き方の人は確かにちらほら見かけましたね、ご意見ありがとうございます

non_zero_indices.append(i)

nums_non_zero = len(non_zero_indices)
for i in range(nums_len):
Copy link

Choose a reason for hiding this comment

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

nums[i] = nums[non_zero_indices[i]]

を行うループと、

nums[i] = 0

を行うループに分けたほうがシンプルだと思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

これは少し迷いましたがそれでも良いですね

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.

4 participants