๋ฌธ์
ํ์ด ๊ณผ์
ํ์ค์นผ ์ผ๊ฐํ์ ๊ตฌํํ๋ ๋ฌธ์ ์
๋๋ค.
1๋ฒ์งธ ํ๊ณผ 2๋ฒ์งธ ํ์ ๊ฐ๊ฐ [1]
๊ณผ [1, 1]
๋ก ๋ฐ๋ก ์ฒ๋ฆฌํด์ฃผ๊ณ
๋๋จธ์ง ๊ฒฝ์ฐ๋ ๋ง์ง๋ง ํ์ ์ธ์ ํ ์์๋ค์ ๋ํด์ ์๋ก์ด ํ์ ๋ง๋ค๋ฉด ๋ฉ๋๋ค.
์ฝ๋
/**
* @param {number} numRows
* @return {number[][]}
*/
var generate = function (numRows) {
const answer = [];
let walker = 1;
while (walker <= numRows) {
if (walker === 1) answer.push([1]);
else if (walker === 2) answer.push([1, 1]);
else {
const lastRow = answer[answer.length - 1];
const temp = [];
for (let i = 0; i < lastRow.length - 1; i++) {
temp.push(lastRow[i] + lastRow[i + 1]);
}
answer.push([1, ...temp, 1]);
}
walker++;
}
return answer;
};
๋ฐ์ํ
'๐ algorithm > leetcode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
LeetCode 3 - Longest Substring Without Repeating Characters (Medium) (0) | 2021.03.03 |
---|---|
LeetCode 89 - Gray Code (Medium) (0) | 2021.03.03 |
LeetCode 19 - Remove Nth Node From End of List (Medium) (0) | 2021.03.03 |
LeetCode 79 - Word Search (Medium) (0) | 2021.03.03 |
LeetCode 771 - Jewels and Stones (Easy) (0) | 2021.03.03 |
๐ฌ ๋๊ธ