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
''' | |
type 0 : -(origimnal*amount/100) | |
type 1 : = amount | |
type 2 : - amount | |
''' | |
products = [ | |
['10','sale','january-sale'], | |
['200','sale','EMPTY'] | |
] |
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
pos = [1,2,4,7] | |
height = [4,6,8,10] | |
maxLeft = [0]*(max(pos)+1) | |
maxRight = [0]*(max(pos)+1) | |
# min(left,right)+1 | |
total = [0]*(max(pos)+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
class Solution: | |
def solve(self, times): | |
times.sort(key=lambda x: x[1]) | |
print(times) | |
counter = 0 | |
end = -1 | |
for i in range(len(times)): | |
print("start:",times[i][0]) | |
print("dy. end:",end) |
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: | |
def multiply(self, num1: str, num2: str) -> str: | |
if num1=="0" or num2=="0": | |
return "0" | |
#print(num1[::-1]) | |
n1 = [] | |
n2 = [] | |
ans = [] | |
for i in num1[::-1]: | |
n1.append(int(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
class Solution: | |
def permuteUnique(self, nums: List[int]) -> List[List[int]]: | |
ans = [] | |
# base | |
if len(nums)==1: | |
return [nums[:]] | |
for i in range(len(nums)): # counter | |
tmp=nums.pop(0) | |
res=self.permuteUnique(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
class Solution: | |
def isValidSerialization(self, preorder: str) -> bool: | |
#print(preorder) | |
# 一個element一個element加 | |
## 過程中 遇到 (number # #) => # | |
## 如果都沒有 (number # #),則繼續一個 element 一個 element 加 | |
stack_list=preorder.split(",") |
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: | |
def permute(self, nums: List[int]) -> List[List[int]]: | |
ans = [] | |
# base | |
if len(nums)==1: | |
return [nums[:]] | |
for i in range(len(nums)): # counter | |
tmp=nums.pop(0) | |
res=self.permute(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
class Node: | |
def __init__(self): | |
self.data = None | |
self.next = None | |
class LinkedList: | |
def __init__(self): | |
self.head = None | |
def addNode(self, data): |
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: | |
def complexNumberMultiply(self, num1: str, num2: str) -> str: | |
#print(num1.split("+")) | |
#print(complex(int(num1[0]),int(num1[0].split("i")[0]))) | |
a = complex(int(num1.split("+")[0]),int(num1.split("+")[1].split("i")[0])) | |
b = complex(int(num2.split("+")[0]),int(num2.split("+")[1].split("i")[0])) | |
print(a) | |
print(b) | |
#print(a*b) |
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, val=0, left=None, right=None): | |
# self.val = val | |
# self.left = left | |
# self.right = right | |
class Solution: | |
def findTarget(self, root: Optional[TreeNode], k: int) -> bool: | |
''' | |
print(root.val) |