Skip to content

Instantly share code, notes, and snippets.

class MedianFinder {
public:
/** initialize your data structure here. */
MedianFinder() {
}
void addNum(int num) {
if(maxPQ.empty() || num <= maxPQ.top())
maxPQ.push(num);
class MedianFinder {
public:
/** initialize your data structure here. */
MedianFinder() {
}
void addNum(int num) {
if(set.empty())
{
/**
* 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 {
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())
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;
struct Dot
{
int x, y;
Dot(int i, int j)
{
x = i;
y = j;
}
struct Dot
{
int x, y;
Dot(int i, int j)
{
x = i;
y = j;
}
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;
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):
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();