Skip to content

Commit 4c6f3b2

Browse files
committed
feat: module
1 parent b86556b commit 4c6f3b2

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ members = [
4242
"open_the_lock",
4343
"maximum_performance_of_a_team",
4444
"longest_consecutive_sequence",
45+
"min_cost_climbing_stairs",
4546
]

longest_consecutive_sequence/src/lib.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
pub struct Solution {}
22

33
impl Solution {
4-
pub fn longest_consecutive(nums: Vec<i32>) -> i32 {}
4+
pub fn longest_consecutive(nums: Vec<i32>) -> i32 {
5+
if nums.len() == 0 {
6+
return 0;
7+
}
8+
9+
let mut numbers = nums.clone();
10+
numbers.sort();
11+
numbers.dedup();
12+
13+
let mut max_length = 0;
14+
let mut temp_length = 1;
15+
for n in numbers.windows(2) {
16+
let j = n[1];
17+
let i = n[0];
18+
if j == i + 1 {
19+
temp_length += 1;
20+
continue;
21+
}
22+
max_length = max_length.max(temp_length);
23+
temp_length = 1;
24+
}
25+
max_length = max_length.max(temp_length);
26+
max_length
27+
}
528
}
629

730
#[cfg(test)]
@@ -15,6 +38,7 @@ mod tests {
1538
assert_eq!(Solution::longest_consecutive(nums.to_vec()), expected);
1639
}
1740

41+
#[test]
1842
fn example_2() {
1943
let nums = [0, 3, 7, 2, 5, 8, 4, 6, 0, 1];
2044
let expected = 9;

min_cost_climbing_stairs/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "min_cost_climbing_stairs"
3+
version = "0.1.0"
4+
authors = ["Ryan Li <conbas2019@gmail.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

min_cost_climbing_stairs/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[cfg(test)]
2+
mod tests {
3+
#[test]
4+
fn it_works() {
5+
assert_eq!(2 + 2, 4);
6+
}
7+
}

0 commit comments

Comments
 (0)