Skip to content

Commit

Permalink
Merge pull request algorithm004-05#1086 from AllenYN/master
Browse files Browse the repository at this point in the history
400-Week 07
  • Loading branch information
melody-li authored Dec 4, 2019
2 parents 154917f + c4e3c4f commit 90c1b9e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Week 7/id_400/LeetCode_190_400.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution {
public:
int hammingWeight(uint32_t n) {
int ret = 0;
while (n != 0) {
n = n & (n - 1);
ret++;
}
return ret;
}
};
11 changes: 11 additions & 0 deletions Week 7/id_400/LeetCode_191_400.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution {
public:
int hammingWeight(uint32_t n) {
int ret = 0;
while (n != 0) {
n = n & (n - 1);
ret++;
}
return ret;
}
};
21 changes: 21 additions & 0 deletions Week 7/id_400/LeetCode_56_400.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& intervals) {
vector<vector<int>> ret;
if(intervals.size() == 0)
return ret;
sort(intervals.begin(), intervals.end());
for (int i = 0; i < intervals.size(); )
{
int left = intervals[i][0];
int right = intervals[i][1];
while (i < intervals.size() - 1 && right >= intervals[i+1][0]) {
i++;
right = max(right, intervals[i][1]);
}
ret.push_back({left, right});
i++;
}
return ret;
}
};

0 comments on commit 90c1b9e

Please sign in to comment.