Skip to content

Instantly share code, notes, and snippets.

View janehwzn's full-sized avatar

Sophie Hu janehwzn

View GitHub Profile
/**
* 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 {
/**
* 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 {
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) {
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;
}
/**
* 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:
var reverseWords = function(str) {
return str.split(' ').reverse().filter(Boolean).join(' ');
};
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;
}
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
@janehwzn
janehwzn / valid anagram
Created August 25, 2015 06:22
valid anagram
class Solution {
public:
bool isAnagram(string s, string t) {
sort(s.begin(), s.end());
sort(t.begin(), t.end());
return s==t;
}
};
@janehwzn
janehwzn / valid anagram
Created August 25, 2015 06:21
valid anagram
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;