Created
July 10, 2020 23:04
-
-
Save RP-3/4c799c680f56532f76afe46d381bb5d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} rowIndex | |
* @return {number[]} | |
*/ | |
var getRow = function(index) { | |
if(index === 0) return [1]; | |
let [result, next] = [[1], []]; | |
for(let row=1; row<=index; row++){ | |
for(let j=0; j<=result.length; j++){ | |
const prev = result[j-1] || 0; | |
const curr = result[j] || 0; | |
next.push(prev + curr); | |
} | |
result = next; | |
next = []; | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment