Skip to content

Search insert position#9

Open
SuperHotDogCat wants to merge 5 commits intoarai60from
search_insert_position
Open

Search insert position#9
SuperHotDogCat wants to merge 5 commits intoarai60from
search_insert_position

Conversation

@SuperHotDogCat
Copy link
Copy Markdown
Owner

@@ -0,0 +1,22 @@
class Solution:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

空行が多い気がします。

elif nums[mid] < target:
left = mid + 1

elif nums[mid] > target:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

else:の方が良さそうです。もしnums[mid] > targetを明示的に示したいならelse: # nums[mid] > targetとコメントにでも書いておけばいかがですか?

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.

phase 4 よいと思います。

@SuperHotDogCat
Copy link
Copy Markdown
Owner Author

phase4までは
if nums[-1] < target:
return len(nums)
を加えていたが, left = 0, right = len(nums) - 1と置いたことでlen(nums)の挿入位置が含まれていない考察になっていることがわかった。なので, left = 0, right = len(nums)とおき, leftに関して開区間, rightに対して閉区間で考えてみた。

@SuperHotDogCat
Copy link
Copy Markdown
Owner Author

でも
if nums[-1] < target:
return len(nums)
で早期returnしてしまった方がよかったでしょうか

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.

3 participants