Skip to content

Commit 1e279cb

Browse files
Merge pull request #3140 from lucasarano/lis
2 parents 1426dbb + 4b50c18 commit 1e279cb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
impl Solution {
2+
pub fn length_of_lis(nums: Vec<i32>) -> i32 {
3+
let mut tails = vec![];
4+
5+
for &num in &nums {
6+
match tails.binary_search(&num) {
7+
Ok(_) => {},
8+
Err(i) => {
9+
if i == tails.len() {
10+
tails.push(num);
11+
} else {
12+
tails[i] = num;
13+
}
14+
}
15+
}
16+
}
17+
tails.len() as i32
18+
}
19+
}

0 commit comments

Comments
 (0)