Skip to content

Commit 47f50cb

Browse files
committed
leetcode
1 parent 1282570 commit 47f50cb

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

‎LeetCode/getRow.cpp‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

‎LeetCode/merge2.cpp‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)