Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] main from itcharge:main #34

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

Merged
pull merged 22 commits into AlgorithmAndLeetCode:main from itcharge:main
Aug 26, 2022
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
096cb11
Update 0167. 两数之和 II - 输入有序数组.md
itcharge Aug 24, 2022
dee78d6
Update 0473. 火柴拼正方形.md
itcharge Aug 25, 2022
70eb9e0
Update 0003. 无重复字符的最长子串.md
itcharge Aug 25, 2022
4073c18
Update 0011. 盛最多水的容器.md
itcharge Aug 25, 2022
f95ab04
Update 0015. 三数之和.md
itcharge Aug 25, 2022
4e75720
Update 0026. 删除有序数组中的重复项.md
itcharge Aug 25, 2022
3b372d4
Update 0080. 删除有序数组中的重复项 II.md
itcharge Aug 25, 2022
4fa1bb6
Update 0125. 验证回文串.md
itcharge Aug 25, 2022
b5c9af4
Update 0167. 两数之和 II - 输入有序数组.md
itcharge Aug 25, 2022
14c770a
Update 0344. 反转字符串.md
itcharge Aug 25, 2022
1084fe7
Update 0349. 两个数组的交集.md
itcharge Aug 25, 2022
7a28f76
Update 1343. 大小为 K 且平均值大于等于阈值的子数组数目.md
itcharge Aug 25, 2022
b3e6cee
Update 01.Array-Two-Pointers.md
itcharge Aug 25, 2022
910d51d
Update 0027. 移除元素.md
itcharge Aug 26, 2022
2d26e41
Update 0209. 长度最小的子数组.md
itcharge Aug 26, 2022
6d0fabe
Update 0220. 存在重复元素 III.md
itcharge Aug 26, 2022
21d9781
Update 0283. 移动零.md
itcharge Aug 26, 2022
cbe4524
Update 0674. 最长连续递增序列.md
itcharge Aug 26, 2022
31eae85
Update 0713. 乘积小于K的子数组.md
itcharge Aug 26, 2022
5662489
Update 1004. 最大连续1的个数 III.md
itcharge Aug 26, 2022
dd52597
Update 01.Array-Sliding-Window.md
itcharge Aug 26, 2022
b36df61
更新题解列表
itcharge Aug 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update 0674. 最长连续递增序列.md
  • Loading branch information
itcharge committed Aug 26, 2022
commit cbe4524ce54ef72d73c83c6f8f4143afd13d62ab
38 changes: 38 additions & 0 deletions Solutions/0674. 最长连续递增序列.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,41 @@ class Solution:
- **时间复杂度**:$O(n)$。一重循环遍历的时间复杂度为 $O(n),ドル最后求最大值的时间复杂度是 $O(n),ドル所以总体时间复杂度为 $O(n)$。
- **空间复杂度**:$O(n)$。用到了一维数组保存状态,所以总体空间复杂度为 $O(n)$。

### 思路 2:滑动窗口(不定长度)

1. 设定两个指针:`left`、`right`,分别指向滑动窗口的左右边界,保证窗口内为连续递增序列。使用 `window_len` 存储当前窗口大小,使用 `max_len` 维护最大窗口长度。
2. 一开始,`left`、`right` 都指向 `0`。
3. 将最右侧元素 `nums[right]` 加入当前连续递增序列中,即当前窗口长度加 `1`(`window_len += 1`)。
4. 判断当前元素 `nums[right] `是否满足连续递增序列。
5. 如果 `right > 0` 并且 `nums[right - 1] >= nums[right]` ,说明不满足连续递增序列,则将 `left` 移动到窗口最右侧,重置当前窗口长度为 `1`(`window_len = 1`)。
6. 记录当前连续递增序列的长度,并更新最长连续递增序列的长度。
7. 继续右移 `right`,直到 `right >= len(nums)` 结束。
8. 输出最长连续递增序列的长度 `max_len`。

### 思路 2:代码

```Python
class Solution:
def findLengthOfLCIS(self, nums: List[int]) -> int:
size = len(nums)
left, right = 0, 0
window_len = 0
max_len = 0

while right < size:
window_len += 1

if right > 0 and nums[right - 1] >= nums[right]:
left = right
window_len = 1

max_len = max(max_len, window_len)
right += 1

return max_len
```

### 思路 2:复杂度分析

- **时间复杂度**:$O(n)$。
- **空间复杂度**:$O(1)$。

AltStyle によって変換されたページ (->オリジナル) /