-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path118.cpp
More file actions
35 lines (32 loc) · 790 Bytes
/
118.cpp
File metadata and controls
35 lines (32 loc) · 790 Bytes
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
29
30
31
32
33
34
35
//
// 118.cpp
// LeetCode
//
// Created by 张佐玮 on 15/8/1.
// Copyright (c) 2015年 JarvisZhang. All rights reserved.
//
// Title: Pascal's Triangle
//
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> results;
if (numRows < 1) {
return results;
}
results.push_back({1});
for (int i = 1; i < numRows; i++) {
vector<int> current;
current.push_back(1);
for (int j = 1; j < i; j++) {
current.push_back(results.back()[j] + results.back()[j-1]);
}
current.push_back(1);
results.push_back(current);
}
return results;
}
};