# 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 isSymmetric(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
if root == None:
return True
return self.help(root.left, root.right)
def help(self, p ...- read more
About
Hello, I'm Haven Shi, a software developer at NJ. I’m passionate about using technology to work more effectively. Right now I’m working on big data platform and UI projects, with various technologies including Java, Python, Scala, Hadoop, Spark Streaming, SQL, and Spring Framework. I have years of ...
read more100. Same Tree
read more# 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 isSameTree(self, p, q): """ :type p: TreeNode :type q: TreeNode :rtype: bool """ if p == None and q == None: return True if p and q ...
98. Validate Binary Search Tree
read more# 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 isValidBST(self, root): """ :type root: TreeNode :rtype: bool """ return self.dfs(root, min=float('-inf'), max=float('inf')) def dfs(self, root, min, max ...
96. Unique Binary Search Trees
read moreclass Solution(object): def numTrees(self, n): """ :type n: int :rtype: int """ nums = [0] * (n + 1) nums[0] = 1 nums[1] = 1 if n == 0 or n == 1: return 1 for i in range(2, n + 1): result = 0 for j in range(0, i): result += nums[j] * nums[i ...
95. Unique Binary Search Trees II
read more# 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 generateTrees(self, n): """ :type n: int :rtype: List[TreeNode] """ if n == 0: return [] return self.dfs(1, n) def dfs(self, start, end): if ...
94. Binary Tree Inorder Traversal
read more# 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 inorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ if root is None: return [] return self.inorderTraversal(root.left) + [root.val]\ + self.inorderTraversal(root ...
93. Restore IP Addresses
read moreclass Solution(object): def restoreIpAddresses(self, s): """ :type s: str :rtype: List[str] """ ans = [] self.helper(ans, s, 4, []) return ['.'.join(x) for x in ans] def helper(self, ans, s, k, temp): if len(s) > k * 3: return '' elif k == 0: ans.append(temp) else: for i in range ...
92. Reverse Linked List II
read more# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def reverseBetween(self, head, m, n): """ :type head: ListNode :type m: int :type n: int :rtype: ListNode """ if m == n: return head cons = ListNode(0) cons.next = head cur = cons ...
Personified Bank's Department Characters
These pictures are drawn when I worked in Bank of China.
Personified characters has a growing popularity in Japan. It means draw a series of things, like food, courses, countries or even programming language as certain kinds of cartoon characters. It could be also used to departments.
When I worked ...
read more