File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < vector>
2+ #include < iostream>
3+ #include < algorithm>
4+ using namespace std ;
5+
6+ #define REP (i,n ) for (int i=0 ;i<(n);++i)
7+ #define FOR (i,a,b ) for (int i=(a);i<=(b);++i)
8+ #define RFOR (i,a,b ) for (int i=(a);i>=(b);--i)
9+ typedef long long LL ;
10+
11+ class Solution {
12+ public:
13+ vector<int > getRow (int rowIndex) {
14+ vector<int > res (rowIndex + 1 );
15+ res[0 ] = 1 ;
16+ FOR (i,1 ,rowIndex) {
17+ vector<int > t (rowIndex + 1 );
18+ t[0 ] = res[0 ];
19+ t[i] = res[i - 1 ];
20+ FOR (j,1 ,i-1 ) t[j] = res[j - 1 ] + res[j];
21+ res = t;
22+ }
23+ return res;
24+ }
25+ };
26+
27+ int main () {
28+ Solution s;
29+ REP (i,6 ) {
30+ vector<int > res = s.getRow (i);
31+ REP (j,res.size ()) cout << res[j] << " " ;
32+ cout << endl;
33+ }
34+ return 0 ;
35+ }
Original file line number Diff line number Diff line change 1+ #include < vector>
2+ #include < iostream>
3+ #include < algorithm>
4+ using namespace std ;
5+
6+ #define REP (i,n ) for (int i=0 ;i<(n);++i)
7+ #define FOR (i,a,b ) for (int i=(a);i<=(b);++i)
8+ #define RFOR (i,a,b ) for (int i=(a);i>=(b);--i)
9+ typedef long long LL ;
10+
11+ struct Interval {
12+ int start;
13+ int end;
14+ Interval () : start(0 ), end(0 ) {}
15+ Interval (int s, int e) : start(s), end(e) {}
16+ };
17+
18+ class Solution {
19+ public:
20+ vector<Interval> merge (vector<Interval> &intervals) {
21+ vector<Interval> res;
22+ vector<pair<int , int > > mm;
23+ int n = intervals.size ();
24+ if (n == 0 ) return res;
25+ REP (i,n) mm.push_back (make_pair (intervals[i].start , intervals[i].end ));
26+ sort (mm.begin (), mm.end ());
27+ int lt = mm[0 ].first , rt = mm[0 ].second ;
28+ FOR (i,1 ,n-1 ) {
29+ if (mm[i].first <= rt) rt = max (rt, mm[i].second );
30+ else {
31+ res.push_back (Interval (lt, rt));
32+ lt = mm[i].first ;
33+ rt = mm[i].second ;
34+ }
35+ }
36+ res.push_back (Interval (lt, rt));
37+ return res;
38+ }
39+ };
40+
41+ int main () {
42+ return 0 ;
43+ }
You can’t perform that action at this time.
0 commit comments