摘要: 123 买股票最佳时机3 看了好久的题解才看懂 class Solution: def maxProfit(self, prices: List[int]) -> int: if prices == []: return 0 n = len(prices) buy1 = prices[0] buy2 阅读全文
posted @ 2021-12-31 16:46 yi术家 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 119 杨辉三角2 一行一行往下推 class Solution: def getRow(self, rowIndex: int) -> List[int]: if rowIndex == 0: return [1] if rowIndex == 1: return [1,1] rel = [1,1 阅读全文
posted @ 2021-12-31 16:39 yi术家 阅读(37) 评论(0) 推荐(0) 编辑
摘要: 114 二叉树展开为链表 : 反先序遍历 我真是天才 如果是前序遍历的话,根结点没法加入结果,因为这样 本来树的结构和结果会缠绕到一起。 所以想着能不能先加入叶子结点。就想到了反先序 右 左 根 这样的顺序 这样 第一个访问到的就是最右下角那个结点 把他加入结果即可。这样结果就是从下往上构建的了 比 阅读全文
posted @ 2021-12-31 16:33 yi术家 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 103 :锯齿形层序遍历 不谈了 层序会 这个也没啥难得 加了奇 偶层的判断 def zigzagLevelOrder(self, root: TreeNode) -> List[List[int]]: if root == None: return [] que = [] rel = [] cur 阅读全文
posted @ 2021-12-31 16:28 yi术家 阅读(28) 评论(0) 推荐(0) 编辑