Skip to content

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.

4 participants