Skip to content

Commit 7be4275

Browse files
🔥 Day 12
1 parent bcf32c2 commit 7be4275

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
2. [Rotting Oranges](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3418/) ➡️ [CPP Solution](Week2/orangesRotting.cpp)
1919
3. [Excel Sheet Column Number](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3419/) ➡️ [CPP Solution](Week2/titleToNumber.cpp)
2020
4. [H Index](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3420/) ➡️ [CPP Solution](Week2/hIndex.cpp)
21+
5. [Pascal's Triangle II](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3421/) ➡️ [CPP Solution](Week2/pascalTriangle2.cpp)
2122

2223
## Where to find me? 🌟
2324
* [Website](https://akashwho.codes/)

Week2/pascalTriangle2.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
vector<int> getRow(int k) {
4+
vector<int> prev;
5+
prev.push_back(1);
6+
7+
vector<int> res(prev);
8+
9+
for(int i = 1; i <= k; ++i) {
10+
res.clear();
11+
res.push_back(1);
12+
13+
for(int p = 0; p < prev.size() - 1; ++p) {
14+
res.push_back(prev.at(p) + prev.at(p + 1));
15+
}
16+
17+
res.push_back(1);
18+
19+
prev = res;
20+
}
21+
22+
return res;
23+
}
24+
};

0 commit comments

Comments
 (0)