Skip to content

35. Search Insert Position #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

fhiyo
Copy link
Owner

@fhiyo fhiyo commented Jul 15, 2024


```py
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:

Choose a reason for hiding this comment

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

課題の制約でnums contains distinct values sorted in ascending order.とあるので問題ないですが、たとえばnums = [3, 3, 3, 3], target = 3の場合とかの答えが違うくないですか?

Copy link
Owner Author

Choose a reason for hiding this comment

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

そうですね、そこはtargetの値を持つindexならば任意の値が返って良い (毎回違う値でも構わない) だろうという解釈をしました。

Choose a reason for hiding this comment

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

多分, hayashi-ayさんが言いたいのは, bisect_leftみたいに一番左のindexを返しませんかということかな?1stの自前実装はそうなってるんですが, 3rdで変わってるかなという気はします

Copy link
Owner Author

Choose a reason for hiding this comment

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

nums = [3, 3, 3, 3], target = 3 の場合、targetのindexは0から3の何を返しても正しいはずなので、targetが見つかった瞬間その位置を返すのは良いのかなと思ってのコメントでした。 (伝わりますかね?自分が何か誤解してるのかもですが...)

Choose a reason for hiding this comment

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

今回の問題はそれで問題ないです。このあたりの話をしてました。https://discord.com/channels/1084280443945353267/1227464441235509308/1229628764443643935

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