Skip to content

283. Move Zeroes#22

Open
hiro111208 wants to merge 1 commit into
mainfrom
283-move-zeroes
Open

283. Move Zeroes#22
hiro111208 wants to merge 1 commit into
mainfrom
283-move-zeroes

Conversation

@hiro111208
Copy link
Copy Markdown
Owner

This problem: 283. Move Zeroes

Next problem: 252. Meeting Rooms

Comment thread 283_move_zeroes/step1.md
"""
Do not return anything, modify nums in-place instead.
"""
l, r = 0, 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.

l,rは分かりづらいなと思いましたmm
渡しはleft, rightの場合は両端から中心に向かうポインタをイメージするので、この場合はfast, slowだとやっていることにイメージが近い感覚です。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ただ、もう少し意味のある名前のほうがbetterな気がするので、zero_i, nonzero_iなどなんらか位置関係以外の意味を持たせたいです。

Comment thread 283_move_zeroes/step2.md
"""
Do not return anything, modify nums in-place instead.
"""
l, r = 0, 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.

lとrがどちらも0で初期化されると、leftとrightが最初は同じ位置にいることがやはり違和感があるかもしません><
left, rightで定義しているなら別の場所からスタートする存在であってほしい気持ちがあります。

Comment thread 283_move_zeroes/step3.md
for i in range(len(nums)):
if nums[i] != 0:
nums[i], nums[non_zero_index] = nums[non_zero_index], nums[i]
zero_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.

non_zero_indexのtypoですかね👀

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PRを上げる前にLeetCodeをパスするか確認しておくと良さそうです。
テストを書くというアイデアもあると思います。

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.

ご指摘ありがとうございます。
こちらタイポです。正しくはzero_indexです。

Comment thread 283_move_zeroes/step3.md
Comment on lines +15 to +19
1回目: 1分 9秒

2回目: 1分 2秒

3回目: 0分 56秒
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

この速度でコード書いているの素晴らしいですね。
逆にもう少しブラッシュアップする時間をとっても良さそうだと思いました。

Comment thread 283_move_zeroes/step2.md
"""
Do not return anything, modify nums in-place instead.
"""
non_zero_index = 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.

non_zero_indexというよりは非ゼロの書き込み場所ぐらいの名前のほうが実態と合っている気がしました。
non_zero_indexで配列にアクセスしてゼロが得られることがあるのは少し違和感があります。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

名前についての議論は色々あるので読んでみると良いかもしれません。

Comment thread 283_move_zeroes/.DS_Store
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LeetCodeとは関係ないですが、git管理する必要がないファイルは.gitignoreで指定しておくと良さそうです。

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