mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
Update 0300.最长上升子序列.md
0300.最长上升子序列的新增C语言实现
This commit is contained in:
@ -288,6 +288,36 @@ function lengthOfLIS(nums: number[]): number {
|
||||
};
|
||||
```
|
||||
|
||||
### C:
|
||||
|
||||
```c
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
int lengthOfLIS(int* nums, int numsSize) {
|
||||
if(numsSize <= 1){
|
||||
return numsSize;
|
||||
}
|
||||
int dp[numsSize];
|
||||
for(int i = 0; i < numsSize; i++){
|
||||
dp[i]=1;
|
||||
}
|
||||
int result = 1;
|
||||
for (int i = 1; i < numsSize; ++i) {
|
||||
for (int j = 0; j < i; ++j) {
|
||||
if(nums[i] > nums[j]){
|
||||
dp[i] = max(dp[i], dp[j] + 1);
|
||||
}
|
||||
if(dp[i] > result){
|
||||
result = dp[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Rust:
|
||||
|
||||
```rust
|
||||
@ -311,4 +341,3 @@ pub fn length_of_lis(nums: Vec<i32>) -> i32 {
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
Reference in New Issue
Block a user