| 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() { |