Skip to content

Commit 8ec201e

Browse files
committed
Add Javascript solution to Leetcode problem 2017 (https://leetcode.com/problems/grid-game/)
1 parent 0446ab9 commit 8ec201e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

javascript/2017-grid-game.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Submission Details:
3+
* https://leetcode.com/problems/grid-game/
4+
* Time O(n), Space O(1)
5+
* Runtime: 89ms (beats 79.31%) || 53.5mb (beats 89.66%)
6+
*/
7+
8+
/**
9+
* @param {number[][]} grid
10+
* @return {number}
11+
*/
12+
13+
var gridGame = function(grid) {
14+
let one = grid[0].reduce((a,b)=>a+b) - grid[0][0];
15+
let two = 0;
16+
let res = one;
17+
for(let i = 1; i < grid[0].length; i++){
18+
one-=grid[0][i];
19+
two+=grid[1][i-1];
20+
res = Math.min(res, Math.max(one,two));
21+
}
22+
return res;
23+
};

0 commit comments

Comments
 (0)