-
Notifications
You must be signed in to change notification settings - Fork 0
Solved: 300. Longest Increasing Subsequence #31
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
base: main
Are you sure you want to change the base?
Conversation
| - numsをはじめから見ていって、各長さのLISにおける末尾の最小値を保持するやり方もあった | ||
| - 発想も素直な気がするのでこれは思いついても良さそうだった | ||
| - ついでに`bisect_left`の実装をみたが、変数名が雑すぎるなあ | ||
| - https://github.com/python/cpython/blob/3.13/Lib/bisect.py#L74 |
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.
docstringをきちんと書いているからOKなんですかね。
| def lengthOfLIS(self, nums: List[int]) -> int: | ||
| length_lis = [1] * len(nums) | ||
| for index in range(len(nums)): | ||
| for former_index in range(index): |
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.
レビューありがとうございます。
見返してみると、
階層が深くなっているので関数化するのもありな気がしてきました。
| if insertion_position == len(tails): | ||
| tails.append(num) | ||
| else: | ||
| tails[insertion_position] = num |
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 insertion_position < len(tails):
tails[insertion_position] = num
else:
tails.append(num)趣味の範囲です。
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.
レビューありがとうございます。
確かに「収まっている場合->収まっていない場合」となっていた方が自然ですね。
| length_lis = [1] * len(nums) | ||
| for index in range(len(nums)): | ||
| for former_index in range(index): | ||
| if nums[index] > nums[former_index]: |
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.
ネスト深めなので、早期continueしたい気もします。
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.
すみません。コメント見逃しておりました。
自分も、コード見返していたところ、同じ感想を持ちました。
300. Longest Increasing Subsequence