Skip to content

35. Search Insert Position#21

Open
hiro111208 wants to merge 1 commit into
mainfrom
35-search-insert-position
Open

35. Search Insert Position#21
hiro111208 wants to merge 1 commit into
mainfrom
35-search-insert-position

Conversation

@hiro111208
Copy link
Copy Markdown
Owner

This problem: 35. Search Insert Position

Next problem: 283. Move Zeros

Copy link
Copy Markdown

@5ky7 5ky7 left a comment

Choose a reason for hiding this comment

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

こちらの進め方を参考にgithub上の他の人のプルリクエスト,あるいはコメント集を見てみると良いでしょう.

Comment on lines +11 to +12
if nums[middle_index] == target:
return middle_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.

この部分はあってももちろんいいんですが,ない方が多くの標準ライブラリにある二分探索の実装に近いですね.
目的に応じて使い分けると良いと思います,今回は問題制約から重複がないことがわかっているので,どちらでも良いでしょう.

```python
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
start_index, end_index = 0, len(nums) - 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.

原則 1 行に 1 つの代入文を書いたほうが、読み手にとって読みやすくなると思います。 swap をする場合は例外だと思います。

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