mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
Update 0674.最长连续递增序列.md
0674.最长连续递增序列新增C语言实现
This commit is contained in:
@ -425,6 +425,57 @@ function findLengthOfLCIS(nums: number[]): number {
|
||||
};
|
||||
```
|
||||
|
||||
### C:
|
||||
|
||||
> 动态规划:
|
||||
|
||||
```c
|
||||
int findLengthOfLCIS(int* nums, int numsSize) {
|
||||
if(numsSize == 0){
|
||||
return 0;
|
||||
}
|
||||
int dp[numsSize];
|
||||
for(int i = 0; i < numsSize; i++){
|
||||
dp[i] = 1;
|
||||
}
|
||||
int result = 1;
|
||||
for (int i = 1; i < numsSize; ++i) {
|
||||
if(nums[i] > nums[i - 1]){
|
||||
dp[i] = dp[i - 1] + 1;
|
||||
}
|
||||
if(dp[i] > result){
|
||||
result = dp[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
> 贪心:
|
||||
|
||||
```c
|
||||
int findLengthOfLCIS(int* nums, int numsSize) {
|
||||
int result = 1;
|
||||
int count = 1;
|
||||
if(numsSize == 0){
|
||||
return result;
|
||||
}
|
||||
for (int i = 1; i < numsSize; ++i) {
|
||||
if(nums[i] > nums[i - 1]){
|
||||
count++;
|
||||
} else{
|
||||
count = 1;
|
||||
}
|
||||
if(count > result){
|
||||
result = count;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
@ -432,4 +483,3 @@ function findLengthOfLCIS(nums: number[]): number {
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
Reference in New Issue
Block a user