-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path119.cpp
69 lines (60 loc) · 1.15 KB
/
119.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include <array>
#include <type_traits>
using namespace std;
class Solution{
public:
vector<int> getRow(int rowIndex){
vector<int> Answer(rowIndex+1);
int temp=0;
Answer[0]=1;
for(int i=0;i<rowIndex+1;i++){
temp=0;
for(int j=0;j<=i;j++){
Answer[j]+=temp;
temp=Answer[j]-temp;
}
}
return Answer;
}
};
template<int i,int j>
struct triangle{
const static int value=triangle<i-1,j>::value+triangle<i,j-1>::value;
};
template<int i>
struct triangle<i,0>{
const static int value=1;
};
template<int i>
struct triangle<0,i>{
const static int value=1;
};
template<>
struct triangle<0,0>{
const static int value =1;
};
template <size_t N,size_t ...I>
static constexpr auto Triangle(std::index_sequence<I...>) {
constexpr std::array<int,N+1> nums = {triangle<I,N- I>::value ...};
return nums;
}
template <size_t N>
constexpr static auto Triangle() {
return Triangle<N>(std::make_index_sequence<N+1>{});
}
int main(){
Solution S;
auto X=S.getRow(4);
for(auto x:X){
cout<<x<<" ";
}
cout<<endl;
auto Y=Triangle<4>();
for(auto y:Y){
cout<<y<<" ";
}
cout<<endl;
return 0;
}