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 DiceCombinations(n,combinations): | |
if n == 0: | |
return combinations | |
temp = [] | |
for val in range(1,7): | |
for com in combinations: | |
temp.append(str(val) + str(com)) | |
n -= 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
list1 = [-2,-1,4,-1,-2,1,5,-3] | |
def maxsum(list1): | |
if list1 != None: | |
max_so_far = list1[0] | |
max_here = list1[0] | |
for val in list1[1:]: | |
max_here = max_here + 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
def Binarydepth(self,root): | |
if root!= None: | |
return 1 + max(self.Binarydepth(root.left),self.Binarydepth(root.right)) | |
else: | |
return 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 PostOrder(self,root): | |
if root!= None: | |
print root.val | |
if root.left!= None: | |
self.PostOrder(root.left) | |
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(object): | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class Solution(object): | |
def rightSideView(self, root): |
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
list1= ['a','b',['c','d',['e','f']],'j',['k','l']] | |
def print_flat(list1,appendStr=''): | |
if isinstance(list1, str): | |
print appendStr + ' ' + list1 | |
else: | |
for i,val in enumerate(list1): | |
print_flat(val, appendStr + (lambda x: "." if x != "" else "")(appendStr) + str(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
list1 = [1,2,2,3,4,5,6,9] | |
def pair_sums(nums,n): | |
dict_nums = {} | |
result = [] | |
nums.sort() | |
for val in nums: | |
if dict_nums.has_key(val): | |
dict_nums[val] += 1 | |
else: | |
dict_nums[val] = 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
'''Given an integer between 0 and 999,999, print an English phrase that describes the integer (eg, “One Thousand, Two Hundred and Thirty Four”).''' | |
dict_units = {0:'',1:'one',2:'two',3:'three',4:'four',5:'five', | |
6:'six',7:'seven',8:'eight',9:'nine'} | |
dict_tens = {0:'',10: 'ten',20:'twenty',30:'thirty',40:'fourty',50:'fifty',60:'sixty',70:'seventy',80:'eighty',90:'ninty'} | |
steps = {0: '', 1:'thousand', 2 : 'million', 3: 'billion'} | |
def exp(n): | |
strn = str(n) | |
if len(strn) == 3 : |
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 rotate( nums, k): | |
""" | |
:type nums: List[int] | |
:type k: int | |
:rtype: void Do not return anything, modify nums in-place instead. | |
""" | |
if len(nums)==1: | |
if k ==1: | |
return nums | |
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
list1 = [10,20,3000,10,-1,12000,-10,20,80,300,100,-30,90,10000] | |
i = 1 | |
j = 1 | |
maxtotal = 0 | |
index_subset = {} | |
total = [] | |
result = [] | |
for val in list1: | |
tempmax= maxtotal+val |
NewerOlder