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
#include <iostream> | |
using namespace std; | |
// y = 2^0 * x * a0 + 2^1 * x * a1 + ... + 2 ^ k * x * ak | |
int divide(unsigned x, unsigned y) { | |
int result = 0; | |
while (y >= x) { | |
int power = 1; |
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
#include <iostream> | |
#include <vector> | |
#include <queue> | |
using namespace std; | |
struct TreeNode { | |
int val; | |
TreeNode *left, *right; | |
TreeNode(int v): val(v), left(NULL), right(NULL) {} |
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
#include <iostream> | |
#include <vector> | |
#include <map> | |
#include <set> | |
#include <stack> | |
#include <queue> | |
#include <unordered_map> | |
#include <unordered_set> | |
#include <climits> |
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
ef add(self, val): | |
if self.size >= self.m * self.n: | |
return False | |
i, j = self.m-1, self.n-1 | |
self.mat[i][j] = val | |
while True: | |
ni, nj = i, j | |
if i > 0 and self.mat[i-1][j] > self.mat[ni][nj]: | |
ni, nj = i-1, j | |
if j > 0 and self.mat[i][j-1] > self.mat[ni][nj]: |
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 TreeNode: | |
def __init__(self, val): | |
self.children, self.val = [], val | |
class PostorderIterator: | |
def __init__(self, root): | |
self.st = [] |
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
ALPHABETSIZE = 26 | |
def get_index(c): | |
return ord(c)-ord('a') | |
class PostfixNode: | |
def __init__(self): |
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
ALPHABETSIZE = 26 | |
def get_index(c): | |
return ord(c)-ord('a') | |
class PostfixTreeNode: |
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
import heapq | |
class Vertex: | |
def __init__(self, val): | |
self.val = val | |
self.adjs = {} | |
def add_edge(self, j, val): | |
self.adjs[j] = val |
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
# -*- coding: utf-8 -*- | |
import random | |
import sys | |
def random_select(a): | |
ret = a[0] | |
for i in range(1, len(a)): | |
j = random.randint(0, i) | |
if j == 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
#include <iostream> | |
using namespace std; | |
void removeContinuous(string &s) { | |
int n = s.size(); | |
int i = 1, j = 0; | |
while (i < n) { | |
if (s[i] != s[j]) { | |
s[++j] = s[i]; |
OlderNewer