Skip to content

Commit e6fd148

Browse files
authored
feat: add rust solution to lc problem: No.0674 (doocs#1262)
1 parent c9df0f1 commit e6fd148

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,32 @@ public:
131131
};
132132
```
133133
134+
### **Rust**
135+
136+
```rust
137+
impl Solution {
138+
#[allow(dead_code)]
139+
pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {
140+
let n = nums.len();
141+
// Here dp[i] represents the longest lcis that ends with `nums[i]`, should be 1 by default
142+
let mut dp: Vec<i32> = vec![1; n];
143+
let mut ret = dp[0];
144+
145+
// Let's dp
146+
for i in 1..n {
147+
dp[i] = if nums[i] > nums[i - 1] {
148+
dp[i - 1] + 1
149+
} else {
150+
1
151+
};
152+
ret = std::cmp::max(ret, dp[i]);
153+
}
154+
155+
ret
156+
}
157+
}
158+
```
159+
134160
### **Go**
135161

136162
```go

solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md

+26
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ public:
115115
};
116116
```
117117
118+
### **Rust**
119+
120+
```rust
121+
impl Solution {
122+
#[allow(dead_code)]
123+
pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {
124+
let n = nums.len();
125+
// Here dp[i] represents the longest lcis that ends with `nums[i]`, should be 1 by default
126+
let mut dp: Vec<i32> = vec![1; n];
127+
let mut ret = dp[0];
128+
129+
// Let's dp
130+
for i in 1..n {
131+
dp[i] = if nums[i] > nums[i - 1] {
132+
dp[i - 1] + 1
133+
} else {
134+
1
135+
};
136+
ret = std::cmp::max(ret, dp[i]);
137+
}
138+
139+
ret
140+
}
141+
}
142+
```
143+
118144
### **Go**
119145

120146
```go
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
impl Solution {
2+
#[allow(dead_code)]
3+
pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {
4+
let n = nums.len();
5+
// Here dp[i] represents the longest lcis that ends with `nums[i]`, should be 1 by default
6+
let mut dp: Vec<i32> = vec![1; n];
7+
let mut ret = dp[0];
8+
9+
// Let's dp
10+
for i in 1..n {
11+
dp[i] = if nums[i] > nums[i - 1] {
12+
dp[i - 1] + 1
13+
} else {
14+
1
15+
};
16+
ret = std::cmp::max(ret, dp[i]);
17+
}
18+
19+
ret
20+
}
21+
}

0 commit comments

Comments
 (0)