- 博客(10)
- 收藏
- 关注
原创 120. 三角形最小路径和
https://leetcode-cn.com/problems/triangle/submissions/dp,自底向上class Solution: def minimumTotal(self, triangle): """ :type triangle: List[List[int]] :rtype: int """...
2018-12-30 23:14:51 102
原创 119. 杨辉三角 II
https://leetcode-cn.com/problems/pascals-triangle-ii/class Solution: def getRow(self, rowIndex): """ :type rowIndex: int :rtype: List[int] """ res...
2018-12-28 17:55:16 111
原创 118. 杨辉三角
https://leetcode-cn.com/problems/pascals-triangle/class Solution: def generate(self, numRows): """ :type numRows: int :rtype: List[List[int]] """ if numRow...
2018-12-28 17:53:08 125
原创 117. 填充同一层的兄弟节点 II
https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii/和116一样层序import Queueclass Solution: # @param root, a tree link node # @return nothing def connect(self, r...
2018-12-28 17:51:26 158
原创 116. 填充同一层的兄弟节点
https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node/comments/# Definition for binary tree with next pointer.# class TreeLinkNode:# def __init__(self, x):# self...
2018-12-25 16:32:11 105
原创 114. 二叉树展开为链表
https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list/submissions/class Solution: def flatten(self, root): """ :type root: TreeNode :rtype: void Do not retur...
2018-12-25 15:51:33 112
原创 113. 路径总和 II
https://leetcode-cn.com/problems/path-sum-ii/思路:回溯法。class Solution: def pathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: List[List[int]]...
2018-12-23 17:53:41 182
原创 112. 路径总和
https://leetcode-cn.com/problems/path-sum/思路:dfs,每次用sum减去当前节点的值,直到sum为0class Solution: def hasPathSum(self, root, sum): """ :type root: TreeNode :type sum: int :r...
2018-12-23 16:37:53 188
原创 111. 二叉树的最小深度
https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/思路1:dfs递归class Solution: def minDepth(self, root): """ :type root: TreeNode :rtype: int """ ...
2018-12-22 23:21:52 118
原创 110. 平衡二叉树
思路:后序遍历,对root的左右子树递归,每次计算root的左右子树高,然后计算root的高,为左右较高者+1.若左右之差大于1,全局flag为false# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self....
2018-12-22 17:31:54 116
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人