Skip to content

Commit 529c024

Browse files
author
Joseph Luce
authored
Update 300_longest_increasing_subsequence.md
1 parent 3c69972 commit 529c024

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

leetcode/medium/300_longest_increasing_subsequence.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88
If we were to start from the left to the right, we would have seen the longest subsequence on the left side as we are going to the right.
99
Inorder for us to know what those longest subsequences were, we will need a way to store that, hello dynamic programming.
1010

11-
For each element, we would need look at the numbers less than the current element on the left side.
11+
For each element, we would need look at the numbers on the left that are less than the current element.
1212
Now that we know which numbers those are, we can then look at their corresponding longest subsequence in the dynamic programming array.
1313
From this list, get the longest subsequence.
14-
This will tell us what to set as our longest subsequence for this current element + 1.
1514

1615
We are basically building the longest increasing subsequence from the bottom up.
1716

1817
**Example:**
19-
20-
I(Input): [10,9,2,5,3,7,101,18]
21-
22-
DP: [1,1,1,1,1,1,1,1]
23-
24-
1. DP[1] = 1 + max([]) **(I[1] not > I[0])**
25-
2. DP[2] = 1 + max([]) **(I[2] not > I[0],I[1])**
26-
3. DP[3] = 1 + max(DP[2]) **(I[3] > I[2] and I[3] not > I[0],I[1])**
27-
4. DP[4] = 1 + max(DP[2]) **(I[4] > I[2] and I[4] not > I[0],I[1],I[3])**
28-
5. DP[5] = 1 + max(DP[1], DP[2], DP[3]) **(I[5] > I[1],I[2],I[3] and I[5] not > I[0])**
29-
6. DP[6] = 1 + max(DP[0], DP[1], DP[2], DP[3], DP[4], DP[5]) **(I[6] > all prev numbers)**
30-
7. DP[7] = 1 + max(DP[0], DP[1], DP[2], DP[3], DP[4], DP[5]) **(I[7] > all prev numbers except I[6])**
18+
```
19+
Input(I): [10,9,2,5,3,7,101,18]
20+
21+
DP:
22+
10 [1, 1, 1, 1, 1, 1, 1, 1]
23+
9 [1, 1, 1, 1, 1, 1, 1, 1] -> DP[1] = 1 + max([]) (I[1] not > I[0])
24+
2 [1, 1, 1, 1, 1, 1, 1, 1] -> DP[2] = 1 + max([]) (I[2] not > I[0],I[1])
25+
5 [1, 1, 1, 2, 1, 1, 1, 1] -> DP[3] = 1 + max(DP[2]) (I[3] > I[2] and I[3] not > I[0],I[1])
26+
3 [1, 1, 1, 2, 2, 1, 1, 1] -> DP[4] = 1 + max(DP[2]) (I[4] > I[2] and I[4] not > I[0],I[1],I[3])
27+
7 [1, 1, 1, 2, 2, 3, 1, 1] -> DP[5] = 1 + max(DP[1], DP[2], DP[3]) (I[5] > I[1],I[2],I[3] and I[5] not > I[0])
28+
101 [1, 1, 1, 2, 2, 3, 4, 1] -> DP[6] = 1 + max(DP[0], DP[1], DP[2], DP[3], DP[4], DP[5]) (I[6] > all prev numbers)
29+
18 [1, 1, 1, 2, 2, 3, 4, 4] -> DP[7] = 1 + max(DP[0], DP[1], DP[2], DP[3], DP[4], DP[5]) (I[7] > all prev numbers except I[6])
30+
```
3131

3232
```
3333
class Solution:

0 commit comments

Comments
 (0)