Skip to content

Commit

Permalink
Add Javascript solution to Leetcode problem 2017 (https://leetcode.co…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesBaxtuh committed Aug 6, 2023
1 parent 0446ab9 commit 8ec201e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions javascript/2017-grid-game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Submission Details:
* https://leetcode.com/problems/grid-game/
* Time O(n), Space O(1)
* Runtime: 89ms (beats 79.31%) || 53.5mb (beats 89.66%)
*/

/**
* @param {number[][]} grid
* @return {number}
*/

var gridGame = function(grid) {
let one = grid[0].reduce((a,b)=>a+b) - grid[0][0];
let two = 0;
let res = one;
for(let i = 1; i < grid[0].length; i++){
one-=grid[0][i];
two+=grid[1][i-1];
res = Math.min(res, Math.max(one,two));
}
return res;
};

0 comments on commit 8ec201e

Please sign in to comment.