This file contains hidden or 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 MedianFinder { | |
public: | |
/** initialize your data structure here. */ | |
MedianFinder() { | |
} | |
void addNum(int num) { | |
if(maxPQ.empty() || num <= maxPQ.top()) | |
maxPQ.push(num); |
This file contains hidden or 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 MedianFinder { | |
public: | |
/** initialize your data structure here. */ | |
MedianFinder() { | |
} | |
void addNum(int num) { | |
if(set.empty()) | |
{ |
This file contains hidden or 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 an interval. | |
* struct Interval { | |
* int start; | |
* int end; | |
* Interval() : start(0), end(0) {} | |
* Interval(int s, int e) : start(s), end(e) {} | |
* }; | |
*/ | |
class Solution { |
This file contains hidden or 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 kEmptySlots(vector<int>& flowers, int k) { | |
int len = flowers.size(); | |
set<int> bloom; | |
for(int i = 0; i < len; ++i) | |
{ | |
int pos = flowers[i]; | |
auto iter = bloom.insert(pos).first; | |
if(iter != bloom.begin()) |
This file contains hidden or 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 kEmptySlots(vector<int>& flowers, int k) { | |
int n = flowers.size(); | |
//days[i] represent the day when flower at i blooms | |
vector<int> days(n, -1); | |
for(int i = 0; i < n; ++i) | |
{ | |
int idx = flowers[i]; | |
days[idx - 1] = i + 1; |
This file contains hidden or 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
struct Dot | |
{ | |
int x, y; | |
Dot(int i, int j) | |
{ | |
x = i; | |
y = j; | |
} | |
This file contains hidden or 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
struct Dot | |
{ | |
int x, y; | |
Dot(int i, int j) | |
{ | |
x = i; | |
y = j; | |
} | |
This file contains hidden or 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: | |
// Encodes a URL to a shortened URL. | |
string encode(string longUrl) { | |
int base = 62, id = _id++; | |
string res = ""; | |
while(id) | |
{ | |
int digit = id % base; |
This file contains hidden or 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
import urllib2 | |
def get_all_links(page): | |
#extract all links from the html page | |
def get_page(link): | |
#get the html page | |
def addTasks(tasks, newTasks): |
This file contains hidden or 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
struct Node | |
{ | |
vector<pair<int, string>> sentences; | |
unordered_map<char, Node*> children; | |
}; | |
class AutocompleteSystem { | |
public: | |
AutocompleteSystem(vector<string> sentences, vector<int> times) { | |
root = new Node(); |