Skip to content

Commit e146bd9

Browse files
committed
Create lcp-61-6CE719.rs
1 parent 46e643a commit e146bd9

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lcp-61-6CE719.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
pub fn temperature_trend(temperature_a: Vec<i32>, temperature_b: Vec<i32>) -> i32 {
2+
let (mut trend_a, mut trend_b) = (vec![], vec![]);
3+
for i in 1..temperature_a.len() {
4+
if temperature_a[i] - temperature_a[i-1] > 0 {
5+
trend_a.push(1);
6+
}
7+
if temperature_a[i] - temperature_a[i-1] == 0 {
8+
trend_a.push(0);
9+
}
10+
if temperature_a[i] - temperature_a[i-1] < 0 {
11+
trend_a.push(-1);
12+
}
13+
if temperature_b[i] - temperature_b[i-1] > 0 {
14+
trend_b.push(1);
15+
}
16+
if temperature_b[i] - temperature_b[i-1] == 0 {
17+
trend_b.push(0);
18+
}
19+
if temperature_b[i] - temperature_b[i-1] < 0 {
20+
trend_b.push(-1);
21+
}
22+
}
23+
let mut last_days = 0;
24+
let mut ret = 0;
25+
for i in 0..trend_a.len() {
26+
if trend_a[i] == trend_b[i] {
27+
last_days += 1;
28+
} else {
29+
if last_days > ret {
30+
ret = last_days
31+
}
32+
last_days = 0;
33+
}
34+
}
35+
if last_days > ret {
36+
ret = last_days
37+
}
38+
println!("{:?} {:?} {:?}", trend_a, trend_b, last_days);
39+
ret
40+
}
41+
42+
43+
fn main() {
44+
let temperature_a = vec![5,10,16,-6,15,11,3];
45+
let temperature_b = vec![16,22,23,23,25,3,-16];
46+
println!("{:?}", temperature_trend(temperature_a, temperature_b));
47+
}

0 commit comments

Comments
 (0)