1. 101. Symmetric Tree

    # 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
  2. 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 more
  3. 100. Same Tree

    # 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 ...
    read more
  4. 98. Validate Binary Search Tree

    # 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 ...
    read more
  5. 96. Unique Binary Search Trees

    class 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 ...
    read more
  6. 95. Unique Binary Search Trees II

    # 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 ...
    read more
  7. 94. Binary Tree Inorder Traversal

    # 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 ...
    read more
  8. 93. Restore IP Addresses

    class 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 ...
    read more
  9. 92. Reverse Linked List II

    # 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 ...
    read more
  10. 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

« Page 9 / 23 »

blogroll

social