일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- dotenv
- bash
- git
- webpack
- docker
- generic
- leetcode
- nginx
- vuetify
- AI
- loop
- machine learning
- JavaScript
- TypeScript
- property
- condition
- C#
- Clone
- BOJ
- var
- Python
- npm
- vue.js
- 앙상블
- type
- VUE
- scss
- C++
- 보안
- security
Archives
- Today
- Total
ice rabbit programming
[LeetCode] Pascal's Triangle 본문
728x90
https://leetcode.com/problems/pascals-triangle/
Pascal's Triangle - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
윗 열 두 개의 합이 아래 원소가 되는 파스칼 삼각형 문제이다. 정직하게 구현했다.
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> pascal;
if(numRows<1)
return pascal;
pascal.push_back({1});
if(numRows==1)
return pascal;
pascal.push_back({1,1});
if(numRows==2)
return pascal;
for(int i=2;i<numRows;i++) {
vector<int> temp;
temp.push_back(1);
for(int j=1;j<=i-1;j++)
temp.push_back(pascal[i-1][j-1]+pascal[i-1][j]);
temp.push_back(1);
pascal.push_back(temp);
}
return pascal;
}
};
728x90
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] Same Tree (0) | 2020.04.22 |
---|---|
[LeetCode] Majority Element (0) | 2020.04.21 |
[LeetCode] Maximum Depth of Binary Tree (feat. 고정관념?) (0) | 2020.04.20 |
[LeetCode] Minimum Depth of Binary Tree (0) | 2020.04.20 |
[LeetCode] Best Time to Buy and Sell Stock (0) | 2020.04.19 |