Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c6c1271

Browse files
committed
src/bin/maximum-population-year.rs
1 parent fbb25bb commit c6c1271

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/bin/maximum-population-year.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
fn main() {}
2+
3+
struct Solution;
4+
5+
impl Solution {
6+
pub fn maximum_population(logs: Vec<Vec<i32>>) -> i32 {
7+
let mut v = vec![0; 1000];
8+
9+
for i in logs {
10+
for x in (i[0] - 1950) as usize..(i[1] - 1950) as usize {
11+
v[x] += 1;
12+
}
13+
}
14+
15+
let mut max = 0;
16+
17+
for i in 1..v.len() {
18+
max = if v[i] > v[max] {
19+
i
20+
} else {
21+
max
22+
}
23+
}
24+
25+
max as i32 + 1950
26+
}
27+
}

0 commit comments

Comments
 (0)