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
/** | |
* 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 { |
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
/** | |
* 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 { |
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
class Solution { | |
public: | |
int findMinArrowShots(vector<pair<int, int>>& points) { | |
if (points.empty()) return 0; | |
int res = 0; | |
int begin = 0, count = 1; | |
std::sort(points.begin(), points.end(), sort_pred()); | |
while(!points.empty()) { | |
while(begin+count < points.size() && points[begin].second >= points[begin+count].first) { |
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
class Node { | |
int val; | |
int index_x, index_y; | |
public: | |
Node (int _val, int _index_x, int _index_y) { | |
val = _val; | |
index_x = _index_x; | |
index_y = _index_y; | |
} |
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
/** | |
* Definition for singly-linked list with a random pointer. | |
* struct RandomListNode { | |
* int label; | |
* RandomListNode *next, *random; | |
* RandomListNode(int x) : label(x), next(NULL), random(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
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
var reverseWords = function(str) { | |
return str.split(' ').reverse().filter(Boolean).join(' '); | |
}; |
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
class Solution { | |
public: | |
int trailingZeroes(int n) { | |
//because 2 is always more than 5, so just count 5. | |
// floor(n/5) + floor(n/25) + floor(n/125) .... until n< 5 ^ i | |
if (n<0) return -1; | |
int res = 0; | |
for (long i = 5; n>=i; i *= 5) { | |
res += n/i; | |
} |
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
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
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
class Solution { | |
public: | |
bool isAnagram(string s, string t) { | |
sort(s.begin(), s.end()); | |
sort(t.begin(), t.end()); | |
return s==t; | |
} | |
}; |
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
class Solution { | |
public: | |
bool isAnagram(string s, string t) { | |
if (s.size() != t.size()) return false; | |
unordered_map<char, int> a, b; | |
for (int i = 0; i<s.size(); i++) { | |
if (a.count(s[i])) { | |
a[s[i]]++; | |
} else { | |
a[s[i]] = 1; |
NewerOlder