Skip to content

Commit

Permalink
Update 0300.最长上升子序列.md
Browse files Browse the repository at this point in the history
0300.最长上升子序列的新增C语言实现
  • Loading branch information
LYT0905 committed Mar 13, 2024
1 parent ec899d6 commit 5f07ae3
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion problems/0300.最长上升子序列.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>

0 comments on commit 5f07ae3

Please sign in to comment.