Skip to content

300. Longest Increasing Subsequence#29

Open
hiro111208 wants to merge 1 commit into
mainfrom
300-longest-increasing-subsequence
Open

300. Longest Increasing Subsequence#29
hiro111208 wants to merge 1 commit into
mainfrom
300-longest-increasing-subsequence

Conversation

@hiro111208
Copy link
Copy Markdown
Owner


- 漸化式を作れなかった
- [NeetCode](https://www.youtube.com/watch?v=cjWnW0hdF1Y)の解法を見た
- LIS[i] を「nums[i] から始まる最長増加部分列の長さ」と定義する
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ある長さの最長増加部分列の末尾の値の最小値を考えることにより、 O(n log n) で解くこともできます。ほかの方の解答を参照されるとよいと思います。

```python
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
LIS = [1] * len(nums)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LIS という名前は定数っぽく感じます。 i 番目の数字で終わる最長増加部分列の長さの最大値が格納されますので、 tail_index_to_max_length はいかがでしょうか?

```python
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
lis_from_i = [1] * len(nums)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

格納されるのが最大の長さのため、 lis とするのは、中身と名前がずれているように思いました。

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.

2 participants