Skip to content

Commit 3c2b7a9

Browse files
committed
Aligned the * and inside code.
1 parent 6dfa481 commit 3c2b7a9

3 files changed

+59
-59
lines changed

0053-maximum-subarray.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ These five steps are a pattern for solving dynamic programming problems.
3232
* `dp[i] = nums[i]` would be good.
3333
3. Determine the `dp` array's recurrence formula
3434
* Use an example:
35-
```
36-
nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
37-
dp = [-2, 1, -2, 4, 3, 5, 6, 1, 5]
38-
```
39-
* After analyzing the sample `dp` data, we can derive the `recurrence formula`:
40-
* `dp[i] = max(nums[i], dp[i - 1] + nums[i])`.
35+
```
36+
nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
37+
dp = [-2, 1, -2, 4, 3, 5, 6, 1, 5]
38+
```
39+
* After analyzing the sample `dp` data, we can derive the `recurrence formula`:
40+
```dp[i] = max(nums[i], dp[i - 1] + nums[i])```
4141
4. Determine the `dp` array's traversal order
4242
* `dp[i]` depends on `dp[i - 1]`, so we should traverse the `dp` array from left to right.
4343
5. Check the `dp` array's value

0392-is-subsequence.md

+28-28
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,35 @@ These five steps are a pattern for solving dynamic programming problems.
2929
* `dp[i][j]` represents whether the first `i` letters of `s` are a subsequence of `t`'s first `j` letters.
3030
* The value of `dp[i][j]` is `true` or `false`.
3131
2. Determine the `dp` array's initial value
32-
* Use an example:
33-
```
34-
After initialized, the 'dp' array would be:
35-
s = "abc", t = "ahbgdc"
36-
# a h b g d c
37-
# T T T T T T T # dp[0]
38-
# a F F F F F F F
39-
# b F F F F F F F
40-
# c F F F F F F F
41-
```
42-
* `dp[0][j] = true` because `dp[0]` represents the empty string, and empty string is a subsequence of any string.
43-
* `dp[i][j] = false (i != 0)`.
32+
* Use an example:
33+
```
34+
After initialized, the 'dp' array would be:
35+
s = "abc", t = "ahbgdc"
36+
# a h b g d c
37+
# T T T T T T T # dp[0]
38+
# a F F F F F F F
39+
# b F F F F F F F
40+
# c F F F F F F F
41+
```
42+
* `dp[0][j] = true` because `dp[0]` represents the empty string, and empty string is a subsequence of any string.
43+
* `dp[i][j] = false (i != 0)`.
4444
3. Determine the `dp` array's recurrence formula
45-
```
46-
The final 'dp' array would be:
47-
s = "abc", t = "ahbgdc"
48-
# a h b g d c
49-
# T T T T T T T
50-
# a F T T T T T T
51-
# b F F F T T T T
52-
# c F F F F F F T
53-
```
54-
* After analyzing the sample `dp` data, we can derive the `recurrence formula`:
55-
```
56-
if s[i - 1] == t[j - 1]
57-
dp[i][j] = dp[i - 1][j - 1]
58-
else
59-
dp[i][j] = dp[i][j - 1]
60-
```
45+
```
46+
The final 'dp' array would be:
47+
s = "abc", t = "ahbgdc"
48+
# a h b g d c
49+
# T T T T T T T
50+
# a F T T T T T T
51+
# b F F F T T T T
52+
# c F F F F F F T
53+
```
54+
* After analyzing the sample `dp` data, we can derive the `recurrence formula`:
55+
```
56+
if s[i - 1] == t[j - 1]
57+
dp[i][j] = dp[i - 1][j - 1]
58+
else
59+
dp[i][j] = dp[i][j - 1]
60+
```
6161
4. Determine the `dp` array's traversal order
6262
* `dp[i][j]` depends on `dp[i - 1][j - 1]` and `dp[i][j - 1]`, so we should traverse the `dp` array from top to bottom, then from left to right.
6363
5. Check the `dp` array's value

0583-delete-operation-for-two-strings.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ These five steps are a pattern for solving dynamic programming problems.
3030
* The value of `dp[i][j]` is an integer.
3131
2. Determine the `dp` array's initial value
3232
* Use an example:
33-
```
34-
After initialized, the 'dp' array would be:
35-
# e a t
36-
# 0 1 2 3 # dp[0]
37-
# s 1 0 0 0
38-
# e 2 0 0 0
39-
# a 3 0 0 0
40-
```
41-
* `dp[0][j] = j`, because `dp[0]` represents the empty string, and the number of steps is just the number of chars to be deleted.
42-
* `dp[i][0] = i`, the reason is the same as previous line, yet in vertical direction.
33+
```
34+
After initialized, the 'dp' array would be:
35+
# e a t
36+
# 0 1 2 3 # dp[0]
37+
# s 1 0 0 0
38+
# e 2 0 0 0
39+
# a 3 0 0 0
40+
```
41+
* `dp[0][j] = j`, because `dp[0]` represents the empty string, and the number of steps is just the number of chars to be deleted.
42+
* `dp[i][0] = i`, the reason is the same as previous line, yet in vertical direction.
4343
3. Determine the `dp` array's recurrence formula
44-
```
45-
The final 'dp' array would be:
46-
# e a t
47-
# 0 1 2 3
48-
# s 1 2 3 4
49-
# e 2 1 2 3
50-
# a 3 2 1 2
51-
```
52-
* After analyzing the sample `dp` data, we can derive the `recurrence formula`:
53-
```python
54-
if word1[i - 1] == word2[j - 1]
55-
dp[i][j] = dp[i - 1][j - 1]
56-
else
57-
dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1
58-
```
44+
```
45+
The final 'dp' array would be:
46+
# e a t
47+
# 0 1 2 3
48+
# s 1 2 3 4
49+
# e 2 1 2 3
50+
# a 3 2 1 2
51+
```
52+
* After analyzing the sample `dp` data, we can derive the `recurrence formula`:
53+
```python
54+
if word1[i - 1] == word2[j - 1]
55+
dp[i][j] = dp[i - 1][j - 1]
56+
else
57+
dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1
58+
```
5959
4. Determine the `dp` array's traversal order
6060
* `dp[i][j]` depends on `dp[i - 1][j - 1]`, `dp[i - 1][j]` and `dp[i][j - 1]`, so we should traverse the `dp` array from top to bottom, then from left to right.
6161
5. Check the `dp` array's value

0 commit comments

Comments
 (0)