Skip to content

Commit 9aae63f

Browse files
author
zhixiong.zhu
committed
feat: solve problem 164
1 parent a1c5dfe commit 9aae63f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

p164-maximum-gap/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "p164-maximum-gap"
3+
version = "0.1.0"
4+
authors = ["zhixiong.zhu <zhixiong.zhu@qq.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]

p164-maximum-gap/src/main.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
struct Solution;
2+
3+
impl Solution {
4+
pub fn maximum_gap(mut nums: Vec<i32>) -> i32 {
5+
nums.sort();
6+
let mut max = 0;
7+
if nums.len() < 2 {
8+
return 0;
9+
}
10+
for i in 0..(nums.len() - 1) {
11+
if (nums[i+1] - nums[i]) > max {
12+
max = nums[i+1] - nums[i];
13+
}
14+
}
15+
max
16+
}
17+
}
18+
19+
fn main() {
20+
println!("{:?}", Solution::maximum_gap(vec![3,6,9,1]));
21+
}

0 commit comments

Comments
 (0)