-
Notifications
You must be signed in to change notification settings - Fork 0
Create 35. Search Insert Position.md #43
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一応ですが、ここで配列を舐めるので線形時間かかりますね。
あと、if not _is_sored(arr): でもいいかなと思いました
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下ではif notにしてますね
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一応ですが、ここで配列を舐めるので線形時間かかりますね。
ご指摘のとおりですね。。。後から加えたのですが、意味なくなっちゃいますね。
あと、if not _is_sored(arr): でもいいかなと思いました 下ではif notにしてますね
有難うございます。ちょっと悩んだので、どっちのパターンも書いてみました。
選択の根拠は、みやすさ以外特に現状ないです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
計算量が悪いコードも実装が単純だと入力次第では好まれることもありますし、あと速いがバグを埋め込みやすいコードの確認などにも使えますね。
計算量がよいこと自体には価値を見出さないほうがいいです。一方で、計算量から見積もられる「計算にかかる時間」はコードの選択の一つのよく使われる基準ではたしかにあります。しかし、基準の一つでしかありません。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odaさん
ありがとうございます。bisect_leftを見たときに疑問に思った点だったので実装しました。
下記覚えておきます。
計算量がよいこと自体には価値を見出さないほうがいいです。一方で、計算量から見積もられる「計算にかかる時間」はコードの選択の一つのよく使われる基準ではたしかにあります。しかし、基準の一つでしかありません。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
さっき出てたのでご覧になったかわかりませんが、これわかりやすかったです
Yoshiki-Iwasa/Arai60#35 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有難うございます!読みました、分かりやすかったです!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここで配列内の全要素見てるので、下で二分探索する意味が無い気がします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ご指摘ありがとうございます。そのとおりですね。元々のbisectになかったので、後から良かれと思って追加しましたが、意味無くなっちゃいますね。以後気をつけます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 行に分けて書いたほうが読みやすいように感じます。
ただし、今回のコードでは関係ナインドエスが、値を swap する場合は 1 行で書いたほうが読みやすいと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちらの方が読みやすく感じました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodechipさん、ありがとうございます。
自分で気づけたのでよかったです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
私はこれは、if にしますが、趣味の範囲でしょう。ところで、少し空行が多い気がします。
https://leetcode.com/problems/search-insert-position/description/