silver-hands / sss

0 stars 0 forks source link

【Q059】119. 杨辉三角 II #59

Open fly0o0 opened 4 years ago

fly0o0 commented 4 years ago

119. 杨辉三角 II

fly0o0 commented 4 years ago
/**
 *  [
 *    [1],
 *    [1,1],
 *    [1,2,1],
 *    [1,3,3,1],
 *    [1,4,6,4,1]
 *  ]
* @param {number} rowIndex
* @return {number[]}
*/
var getRow = function(rowIndex) {
  let kRow = []
  for (let i = 0; i < rowIndex; i++) {
    kRow[0] = 1
    kRow[i] = 1
    for (let j = i - 1; j > 0; j--) {
      kRow[j] = kRow[j - 1] + kRow[j]
    }
  }
  return kRow
};