Skip to content

Commit

Permalink
Update 0300.最长上升子序列.md 优化 Rust 和 Java
Browse files Browse the repository at this point in the history
  • Loading branch information
fwqaaq authored Jul 18, 2023
1 parent f90e8a2 commit a3a8182
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions problems/0300.最长上升子序列.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,16 @@ Java:
class Solution {
public int lengthOfLIS(int[] nums) {
int[] dp = new int[nums.length];
int res = 0;
Arrays.fill(dp, 1);
for (int i = 0; i < dp.length; i++) {
for (int i = 1; i < dp.length; i++) {
for (int j = 0; j < i; j++) {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
res = Math.max(res, dp[i]);
}
}
int res = 0;
for (int i = 0; i < dp.length; i++) {
res = Math.max(res, dp[i]);
}
return res;
}
}
Expand Down Expand Up @@ -291,7 +289,7 @@ function lengthOfLIS(nums: number[]): number {
Rust:
```rust
pub fn length_of_lis(nums: Vec<i32>) -> i32 {
let mut dp = vec![1; nums.len() + 1];
let mut dp = vec![1; nums.len()];
let mut result = 1;
for i in 1..nums.len() {
for j in 0..i {
Expand All @@ -306,13 +304,6 @@ pub fn length_of_lis(nums: Vec<i32>) -> i32 {
```









<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
Expand Down

0 comments on commit a3a8182

Please sign in to comment.