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 findKthNum(int k) | |
{ | |
set<int> bst; | |
bst.insert(1); | |
int curr; | |
for (int i = 0; i < k; ++i) | |
{ | |
curr = *bst.begin(); |
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 BinaryCode { | |
int charToNum(char c) { | |
return c - '0'; | |
} | |
String solve(String message, char[] P, char first) { | |
boolean isValid = true; | |
int N = P.length; | |
P[0] = first; | |
P[1] = (char) ('0' + charToNum(message.charAt(0)) - charToNum(P[0])); |
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
moves = [int('011',base=8), int('0111', base=8), int('01110010', base=8), int('0100100',base=8), int('0101000',base=8), int('010001000',base=8), int('010100000',base=8), int('011000000',base=8)] | |
finalStates = [0, int('1'*8, base=8), int('2'*8, base=8), int('3'*8, base=8)] | |
TERMINAL = int('4'*8, base=8) | |
MASK = int('3'*8, base=8) | |
def code(c): |
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 | |
class TreeNode: | |
def __init__(self, x): | |
self.val = x | |
self.left = None | |
self.right = None | |
self.parent = None | |
def successor(node): | |
# return the tree node which is the successor of this node |
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
def stackInsert(stack, elem): | |
if len(stack) == 0 or stack[len(stack)-1] <= elem: | |
stack.append(elem) | |
else: | |
topElem = stack.pop() | |
stackInsert(stack, elem) | |
stack.append(topElem) | |
def stackSort(stack): | |
if len(stack) == 0: |
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
def Hanoi(num, start, target, aux): | |
stack = [] | |
t = (num, start, target, aux) | |
while t[0] != 0 or len(stack) > 0: | |
if t[0] != 0: | |
stack.append(t) | |
t = (t[0]-1, t[1], t[3], t[2]) | |
else: | |
t = stack.pop() | |
print 'move the '+str(t[0])+'th plate from '+str(t[1])+' to '+str(t[2]) |