Skip to content

Commit

Permalink
Create 2017-grid-game.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
felivalencia3 authored Jul 28, 2023
1 parent bcfc791 commit 7e32272
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rust/2017-grid-game.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
impl Solution {
pub fn grid_game(grid: Vec<Vec<i32>>) -> i64 {
let n = grid[0].len();

let mut memo1 = vec![0;n+1];
let mut memo2 = vec![0;n+1];
for i in 0..n {
memo1[i+1] = memo1[i] + grid[0][i] as i64;
memo2[i+1] = memo2[i] + grid[1][i] as i64;
}

let mut result = i64::max_value();
for i in 0..n {
result = result.min(memo2[i].max(memo1[n] - memo1[i+1]));
}

result
}
}

0 comments on commit 7e32272

Please sign in to comment.