Skip to content

Commit 8747599

Browse files
committed
Add solution 674
1 parent 4c34ef0 commit 8747599

13 files changed

+261
-38
lines changed

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@
126126
| | Easy | Medium | Hard | Total |
127127
|:--------:|:--------:|:--------:|:--------:|:--------:|
128128
|Optimizing|38|45|16|99|
129-
|Accepted|**249**|**321**|**96**|**666**|
129+
|Accepted|**250**|**321**|**96**|**667**|
130130
|Total|461|908|370|1739|
131-
|Perfection Rate|84.7%|86.0%|83.3%|85.1%|
132-
|Completion Rate|54.0%|35.4%|25.9%|38.3%|
131+
|Perfection Rate|84.8%|86.0%|83.3%|85.2%|
132+
|Completion Rate|54.2%|35.4%|25.9%|38.4%|
133133
|------------|----------------------------|----------------------------|----------------------------|----------------------------|
134134

135135
## 二. 目录
136136

137-
以下已经收录了 567 道题的题解,还有 13 道题在尝试优化到 beats 100%
137+
以下已经收录了 568 道题的题解,还有 13 道题在尝试优化到 beats 100%
138138

139139
| No. | Title | Solution | Acceptance | Difficulty | Frequency |
140140
|:--------:|:--------------------------------------------------------------|:--------:|:--------:|:--------:|:--------:|
@@ -444,7 +444,7 @@
444444
|0304|Range Sum Query 2D - Immutable||40.3%|Medium||
445445
|0305|Number of Islands II||39.8%|Hard||
446446
|0306|Additive Number|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0306.Additive-Number)|29.6%|Medium||
447-
|0307|Range Sum Query - Mutable|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0307.Range-Sum-Query---Mutable)|36.5%|Medium||
447+
|0307|Range Sum Query - Mutable|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0307.Range-Sum-Query---Mutable)|36.6%|Medium||
448448
|0308|Range Sum Query 2D - Mutable||37.3%|Hard||
449449
|0309|Best Time to Buy and Sell Stock with Cooldown|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown)|48.1%|Medium||
450450
|0310|Minimum Height Trees||34.5%|Medium||
@@ -608,7 +608,7 @@
608608
|0468|Validate IP Address||24.8%|Medium||
609609
|0469|Convex Polygon||37.4%|Medium||
610610
|0470|Implement Rand10() Using Rand7()|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0470.Implement-Rand10()-Using-Rand7())|46.0%|Medium||
611-
|0471|Encode String with Shortest Length||48.9%|Hard||
611+
|0471|Encode String with Shortest Length||49.0%|Hard||
612612
|0472|Concatenated Words||44.4%|Hard||
613613
|0473|Matchsticks to Square||38.2%|Medium||
614614
|0474|Ones and Zeroes|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0474.Ones-and-Zeroes)|43.5%|Medium||
@@ -811,7 +811,7 @@
811811
|0671|Second Minimum Node In a Binary Tree||42.8%|Easy||
812812
|0672|Bulb Switcher II||51.1%|Medium||
813813
|0673|Number of Longest Increasing Subsequence||38.4%|Medium||
814-
|0674|Longest Continuous Increasing Subsequence||46.0%|Easy||
814+
|0674|Longest Continuous Increasing Subsequence|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0674.Longest-Continuous-Increasing-Subsequence)|46.0%|Easy||
815815
|0675|Cut Off Trees for Golf Event||35.2%|Hard||
816816
|0676|Implement Magic Dictionary|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0676.Implement-Magic-Dictionary)|55.2%|Medium||
817817
|0677|Map Sum Pairs||53.9%|Medium||
@@ -826,7 +826,7 @@
826826
|0686|Repeated String Match||32.8%|Medium||
827827
|0687|Longest Univalue Path||37.1%|Medium||
828828
|0688|Knight Probability in Chessboard||50.0%|Medium||
829-
|0689|Maximum Sum of 3 Non-Overlapping Subarrays||47.1%|Hard||
829+
|0689|Maximum Sum of 3 Non-Overlapping Subarrays||47.2%|Hard||
830830
|0690|Employee Importance||58.5%|Easy||
831831
|0691|Stickers to Spell Word||44.3%|Hard||
832832
|0692|Top K Frequent Words||52.9%|Medium||
@@ -946,7 +946,7 @@
946946
|0806|Number of Lines To Write String||65.5%|Easy||
947947
|0807|Max Increase to Keep City Skyline||84.3%|Medium||
948948
|0808|Soup Servings||40.9%|Medium||
949-
|0809|Expressive Words||46.6%|Medium||
949+
|0809|Expressive Words||46.5%|Medium||
950950
|0810|Chalkboard XOR Game||49.4%|Hard||
951951
|0811|Subdomain Visit Count|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0811.Subdomain-Visit-Count)|71.2%|Easy||
952952
|0812|Largest Triangle Area|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0812.Largest-Triangle-Area)|58.9%|Easy||
@@ -1093,7 +1093,7 @@
10931093
|0953|Verifying an Alien Dictionary|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0953.Verifying-an-Alien-Dictionary)|52.5%|Easy||
10941094
|0954|Array of Doubled Pairs||35.3%|Medium||
10951095
|0955|Delete Columns to Make Sorted II||33.7%|Medium||
1096-
|0956|Tallest Billboard||39.8%|Hard||
1096+
|0956|Tallest Billboard||39.7%|Hard||
10971097
|0957|Prison Cells After N Days||40.2%|Medium||
10981098
|0958|Check Completeness of a Binary Tree||52.4%|Medium||
10991099
|0959|Regions Cut By Slashes|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0959.Regions-Cut-By-Slashes)|66.9%|Medium||
@@ -1363,7 +1363,7 @@
13631363
|1223|Dice Roll Simulation||46.6%|Hard||
13641364
|1224|Maximum Equal Frequency||34.5%|Hard||
13651365
|1225|Report Contiguous Dates||62.6%|Hard||
1366-
|1226|The Dining Philosophers||59.8%|Medium||
1366+
|1226|The Dining Philosophers||59.7%|Medium||
13671367
|1227|Airplane Seat Assignment Probability||62.1%|Medium||
13681368
|1228|Missing Number In Arithmetic Progression||51.6%|Easy||
13691369
|1229|Meeting Scheduler||54.3%|Medium||
@@ -1403,7 +1403,7 @@
14031403
|1263|Minimum Moves to Move a Box to Their Target Location||43.1%|Hard||
14041404
|1264|Page Recommendations||69.1%|Medium||
14051405
|1265|Print Immutable Linked List in Reverse||94.4%|Medium||
1406-
|1266|Minimum Time Visiting All Points|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1266.Minimum-Time-Visiting-All-Points)|79.5%|Easy||
1406+
|1266|Minimum Time Visiting All Points|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1266.Minimum-Time-Visiting-All-Points)|79.4%|Easy||
14071407
|1267|Count Servers that Communicate||57.8%|Medium||
14081408
|1268|Search Suggestions System||64.5%|Medium||
14091409
|1269|Number of Ways to Stay in the Same Place After Some Steps||43.3%|Hard||
@@ -1459,15 +1459,15 @@
14591459
|1319|Number of Operations to Make Network Connected|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1319.Number-of-Operations-to-Make-Network-Connected)|54.9%|Medium||
14601460
|1320|Minimum Distance to Type a Word Using Two Fingers||62.9%|Hard||
14611461
|1321|Restaurant Growth||70.8%|Medium||
1462-
|1322|Ads Performance||57.8%|Easy||
1462+
|1322|Ads Performance||57.7%|Easy||
14631463
|1323|Maximum 69 Number||78.0%|Easy||
14641464
|1324|Print Words Vertically||58.6%|Medium||
14651465
|1325|Delete Leaves With a Given Value||73.6%|Medium||
14661466
|1326|Minimum Number of Taps to Open to Water a Garden||46.3%|Hard||
14671467
|1327|List the Products Ordered in a Period||77.4%|Easy||
14681468
|1328|Break a Palindrome||45.8%|Medium||
14691469
|1329|Sort the Matrix Diagonally|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1329.Sort-the-Matrix-Diagonally)|81.7%|Medium||
1470-
|1330|Reverse Subarray To Maximize Array Value||36.5%|Hard||
1470+
|1330|Reverse Subarray To Maximize Array Value||36.6%|Hard||
14711471
|1331|Rank Transform of an Array||57.7%|Easy||
14721472
|1332|Remove Palindromic Subsequences||62.8%|Easy||
14731473
|1333|Filter Restaurants by Vegan-Friendly, Price and Distance||57.0%|Medium||
@@ -1543,7 +1543,7 @@
15431543
|1403|Minimum Subsequence in Non-Increasing Order||71.1%|Easy||
15441544
|1404|Number of Steps to Reduce a Number in Binary Representation to One||49.9%|Medium||
15451545
|1405|Longest Happy String||52.2%|Medium||
1546-
|1406|Stone Game III||57.3%|Hard||
1546+
|1406|Stone Game III||57.2%|Hard||
15471547
|1407|Top Travellers||83.6%|Easy||
15481548
|1408|String Matching in an Array||62.8%|Easy||
15491549
|1409|Queries on a Permutation With Key||81.4%|Medium||
@@ -1619,7 +1619,7 @@
16191619
|1479|Sales by Day of the Week||83.5%|Hard||
16201620
|1480|Running Sum of 1d Array|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1480.Running-Sum-of-1d-Array)|89.5%|Easy||
16211621
|1481|Least Number of Unique Integers after K Removals||55.6%|Medium||
1622-
|1482|Minimum Number of Days to Make m Bouquets||49.8%|Medium||
1622+
|1482|Minimum Number of Days to Make m Bouquets||49.9%|Medium||
16231623
|1483|Kth Ancestor of a Tree Node||30.4%|Hard||
16241624
|1484|Group Sold Products By The Date||85.9%|Easy||
16251625
|1485|Clone Binary Tree With Random Pointer||79.4%|Medium||
@@ -1795,7 +1795,7 @@
17951795
|1655|Distribute Repeating Integers|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1655.Distribute-Repeating-Integers)|40.5%|Hard||
17961796
|1656|Design an Ordered Stream|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1656.Design-an-Ordered-Stream)|82.1%|Easy||
17971797
|1657|Determine if Two Strings Are Close|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1657.Determine-if-Two-Strings-Are-Close)|55.9%|Medium||
1798-
|1658|Minimum Operations to Reduce X to Zero|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero)|33.3%|Medium||
1798+
|1658|Minimum Operations to Reduce X to Zero|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero)|33.4%|Medium||
17991799
|1659|Maximize Grid Happiness|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1659.Maximize-Grid-Happiness)|35.2%|Hard||
18001800
|1660|Correct a Binary Tree||79.1%|Medium||
18011801
|1661|Average Time of Process per Machine||79.5%|Easy||
@@ -1824,12 +1824,12 @@
18241824
|1684|Count the Number of Consistent Strings|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1684.Count-the-Number-of-Consistent-Strings)|83.9%|Easy||
18251825
|1685|Sum of Absolute Differences in a Sorted Array|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array)|61.7%|Medium||
18261826
|1686|Stone Game VI||49.0%|Medium||
1827-
|1687|Delivering Boxes from Storage to Ports||34.6%|Hard||
1827+
|1687|Delivering Boxes from Storage to Ports||34.7%|Hard||
18281828
|1688|Count of Matches in Tournament|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1688.Count-of-Matches-in-Tournament)|83.0%|Easy||
18291829
|1689|Partitioning Into Minimum Number Of Deci-Binary Numbers|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers)|87.9%|Medium||
18301830
|1690|Stone Game VII|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1690.Stone-Game-VII)|47.0%|Medium||
18311831
|1691|Maximum Height by Stacking Cuboids ||49.9%|Hard||
1832-
|1692|Count Ways to Distribute Candies||61.6%|Hard||
1832+
|1692|Count Ways to Distribute Candies||61.4%|Hard||
18331833
|1693|Daily Leads and Partners||90.8%|Easy||
18341834
|1694|Reformat Phone Number|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1694.Reformat-Phone-Number)|66.9%|Easy||
18351835
|1695|Maximum Erasure Value|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1695.Maximum-Erasure-Value)|49.6%|Medium||
@@ -1842,21 +1842,21 @@
18421842
|1702|Maximum Binary String After Change||61.2%|Medium||
18431843
|1703|Minimum Adjacent Swaps for K Consecutive Ones||40.7%|Hard||
18441844
|1704|Determine if String Halves Are Alike||78.2%|Easy||
1845-
|1705|Maximum Number of Eaten Apples||42.2%|Medium||
1845+
|1705|Maximum Number of Eaten Apples||42.3%|Medium||
18461846
|1706|Where Will the Ball Fall||58.6%|Medium||
18471847
|1707|Maximum XOR With an Element From Array||47.8%|Hard||
18481848
|1708|Largest Subarray Length K||64.4%|Easy||
18491849
|1709|Biggest Window Between Visits||82.5%|Medium||
18501850
|1710|Maximum Units on a Truck||70.8%|Easy||
18511851
|1711|Count Good Meals||25.8%|Medium||
18521852
|1712|Ways to Split Array Into Three Subarrays||29.9%|Medium||
1853-
|1713|Minimum Operations to Make a Subsequence||45.5%|Hard||
1853+
|1713|Minimum Operations to Make a Subsequence||45.4%|Hard||
18541854
|1714|Sum Of Special Evenly-Spaced Elements In Array||47.8%|Hard||
18551855
|1715|Count Apples and Oranges||78.2%|Medium||
18561856
|1716|Calculate Money in Leetcode Bank||68.6%|Easy||
18571857
|1717|Maximum Score From Removing Substrings||39.2%|Medium||
18581858
|1718|Construct the Lexicographically Largest Valid Sequence||44.0%|Medium||
1859-
|1719|Number Of Ways To Reconstruct A Tree||39.4%|Hard||
1859+
|1719|Number Of Ways To Reconstruct A Tree||39.3%|Hard||
18601860
|1720|Decode XORed Array||86.0%|Easy||
18611861
|1721|Swapping Nodes in a Linked List||65.1%|Medium||
18621862
|1722|Minimize Hamming Distance After Swap Operations||55.8%|Medium||
@@ -1866,17 +1866,17 @@
18661866
|1726|Tuple with Same Product||53.9%|Medium||
18671867
|1727|Largest Submatrix With Rearrangements||57.9%|Medium||
18681868
|1728|Cat and Mouse II||40.5%|Hard||
1869-
|1729|Find Followers Count||72.4%|Easy||
1870-
|1730|Shortest Path to Get Food||64.3%|Medium||
1871-
|1731|The Number of Employees Which Report to Each Employee||52.6%|Easy||
1872-
|1732|Find the Highest Altitude||81.8%|Easy||
1873-
|1733|Minimum Number of People to Teach||31.3%|Medium||
1874-
|1734|Decode XORed Permutation||43.4%|Medium||
1875-
|1735|Count Ways to Make Array With Product||39.5%|Hard||
1869+
|1729|Find Followers Count||72.5%|Easy||
1870+
|1730|Shortest Path to Get Food||64.4%|Medium||
1871+
|1731|The Number of Employees Which Report to Each Employee||52.8%|Easy||
1872+
|1732|Find the Highest Altitude||81.9%|Easy||
1873+
|1733|Minimum Number of People to Teach||31.5%|Medium||
1874+
|1734|Decode XORed Permutation||43.7%|Medium||
1875+
|1735|Count Ways to Make Array With Product||39.9%|Hard||
18761876
|1736|Latest Time by Replacing Hidden Digits||41.0%|Easy||
1877-
|1737|Change Minimum Characters to Satisfy One of Three Conditions||23.1%|Medium||
1878-
|1738|Find Kth Largest XOR Coordinate Value||60.0%|Medium||
1879-
|1739|Building Boxes||42.3%|Hard||
1877+
|1737|Change Minimum Characters to Satisfy One of Three Conditions||23.2%|Medium||
1878+
|1738|Find Kth Largest XOR Coordinate Value||60.1%|Medium||
1879+
|1739|Building Boxes||42.5%|Hard||
18801880
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|
18811881

18821882
------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package leetcode
2+
3+
func findLengthOfLCIS(nums []int) int {
4+
if len(nums) == 0 {
5+
return 0
6+
}
7+
res, length := 1, 1
8+
for i := 1; i < len(nums); i++ {
9+
if nums[i] > nums[i-1] {
10+
length++
11+
} else {
12+
res = max(res, length)
13+
length = 1
14+
}
15+
}
16+
return max(res, length)
17+
}
18+
19+
func max(a, b int) int {
20+
if a > b {
21+
return a
22+
}
23+
return b
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package leetcode
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
type question674 struct {
9+
para674
10+
ans674
11+
}
12+
13+
// para 是参数
14+
// one 代表第一个参数
15+
type para674 struct {
16+
nums []int
17+
}
18+
19+
// ans 是答案
20+
// one 代表第一个答案
21+
type ans674 struct {
22+
one int
23+
}
24+
25+
func Test_Problem674(t *testing.T) {
26+
27+
qs := []question674{
28+
29+
{
30+
para674{[]int{1, 3, 5, 4, 7}},
31+
ans674{3},
32+
},
33+
34+
{
35+
para674{[]int{2, 2, 2, 2, 2}},
36+
ans674{1},
37+
},
38+
39+
{
40+
para674{[]int{1, 3, 5, 7}},
41+
ans674{4},
42+
},
43+
}
44+
45+
fmt.Printf("------------------------Leetcode Problem 674------------------------\n")
46+
47+
for _, q := range qs {
48+
_, p := q.ans674, q.para674
49+
fmt.Printf("【input】:%v 【output】:%v\n", p, findLengthOfLCIS(p.nums))
50+
}
51+
fmt.Printf("\n\n\n")
52+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# [674. Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence/)
2+
3+
4+
## 题目
5+
6+
Given an unsorted array of integers `nums`, return *the length of the longest **continuous increasing subsequence** (i.e. subarray)*. The subsequence must be **strictly** increasing.
7+
8+
**continuous increasing subsequence** is defined by two indices `l` and `r` (`l < r`) such that it is `[nums[l], nums[l + 1], ..., nums[r - 1], nums[r]]` and for each `l <= i < r``nums[i] < nums[i + 1]`.
9+
10+
**Example 1:**
11+
12+
```
13+
Input: nums = [1,3,5,4,7]
14+
Output: 3
15+
Explanation: The longest continuous increasing subsequence is [1,3,5] with length 3.
16+
Even though [1,3,5,7] is an increasing subsequence, it is not continuous as elements 5 and 7 are separated by element
17+
4.
18+
```
19+
20+
**Example 2:**
21+
22+
```
23+
Input: nums = [2,2,2,2,2]
24+
Output: 1
25+
Explanation: The longest continuous increasing subsequence is [2] with length 1. Note that it must be strictly
26+
increasing.
27+
```
28+
29+
**Constraints:**
30+
31+
- `0 <= nums.length <= 10^4`
32+
- `10^9 <= nums[i] <= 10^9`
33+
34+
## 题目大意
35+
36+
给定一个未经排序的整数数组,找到最长且 连续递增的子序列,并返回该序列的长度。连续递增的子序列 可以由两个下标 l 和 r(l < r)确定,如果对于每个 l <= i < r,都有 nums[i] < nums[i + 1] ,那么子序列 [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] 就是连续递增子序列。
37+
38+
## 解题思路
39+
40+
- 简单题。这一题和第 128 题有区别。这一题要求子序列必须是连续下标,所以变简单了。扫描一遍数组,记下连续递增序列的长度,动态维护这个最大值,最后输出即可。
41+
42+
## 代码
43+
44+
```go
45+
package leetcode
46+
47+
func findLengthOfLCIS(nums []int) int {
48+
if len(nums) == 0 {
49+
return 0
50+
}
51+
res, length := 1, 1
52+
for i := 1; i < len(nums); i++ {
53+
if nums[i] > nums[i-1] {
54+
length++
55+
} else {
56+
res = max(res, length)
57+
length = 1
58+
}
59+
}
60+
return max(res, length)
61+
}
62+
63+
func max(a, b int) int {
64+
if a > b {
65+
return a
66+
}
67+
return b
68+
}
69+
```

website/content/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ func counterKthNum(m, n, mid int) int {
8787
----------------------------------------------
8888
<div style="display: flex;justify-content: space-between;align-items: center;">
8989
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0662.Maximum-Width-of-Binary-Tree/">⬅️上一页</a></p>
90-
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0676.Implement-Magic-Dictionary/">下一页➡️</a></p>
90+
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0674.Longest-Continuous-Increasing-Subsequence/">下一页➡️</a></p>
9191
</div>

0 commit comments

Comments
 (0)