Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Definition for a binary tree node. | ||
* struct TreeNode { | ||
* int val; | ||
* TreeNode *left; | ||
* TreeNode *right; | ||
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | ||
* }; | ||
*/ | ||
class Solution { | ||
public: | ||
TreeNode* invertTree(TreeNode* root) { | ||
if (root == NULL) { | ||
return root; | ||
} | ||
swap(root->left, root->right); | ||
invertTree(root->left); | ||
invertTree(root->right); | ||
return root; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Solution { | ||
public: | ||
bool isPowerOfTwo(int n) { | ||
if (n <= 0) { | ||
return false; | ||
} | ||
n &= (n - 1); | ||
return n == 0; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
###__Greatness from Basis comes__ | ||
Finished 185/218 | ||
Finished 188/219 | ||
Reetsee.Xu last updated on 2015.07.11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Solution { | ||
public: | ||
vector<string> summaryRanges(vector<int>& nums) { | ||
vector<string> range_vector; | ||
size_t nums_size = nums.size(); | ||
if (nums_size == 0) { | ||
return range_vector; | ||
} | ||
|
||
int last_num = nums[0]; | ||
for (size_t i = 1; i < nums_size; ++i) { | ||
if (nums[i] != nums[i-1] + 1) { | ||
addRange(range_vector, last_num, nums[i-1]); | ||
last_num = nums[i]; | ||
} | ||
} | ||
addRange(range_vector, last_num, nums.back()); | ||
return range_vector; | ||
} | ||
|
||
void addRange(vector<string>& range_vector, int left, int right) { | ||
char range[32]; | ||
if (left == right) { | ||
snprintf(range, sizeof(range), "%d", left); | ||
} else { | ||
snprintf(range, sizeof(range), "%d->%d", left, right); | ||
} | ||
range_vector.push_back(range); | ||
} | ||
}; |