摘要: 160.Intersection of Two Linked Lists 查找并返回AB链表中的交点,若无返回None 方法1: 计算A、B两个链表长度,优先循环长度长的链表,长度差次循环后,依次对比AB 1 class Solution(object): 2 def getIntersection 阅读全文
posted @ 2018-10-23 22:40 adminyzz 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 136. Single Number 方法一:建立字典,依次循环; 1 class Solution: 2 def singleNumber(self, nums): 3 """ 4 :type nums: List[int] 5 :rtype: int 6 """ 7 dict1 = {} 8 f 阅读全文
posted @ 2018-10-22 17:48 adminyzz 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 119. Pascal's Triangle II 返回杨辉三角第n层数字列表,和118类似 1 class Solution: 2 def getRow(self, rowIndex): 3 """ 4 :type rowIndex: int 5 :rtype: List[int] 6 """ 7 阅读全文
posted @ 2018-10-21 19:02 adminyzz 阅读(77) 评论(0) 推荐(0) 编辑
摘要: 111.Minimum Depth of Binary Tree 给定一个二叉树,求其最小深度 如果没有根节点,返回0;如果有根节点,判断左右孩子,有左孩子,返回 左孩子最小深度+1;有右孩子,返回右孩子最小深度+1;左右孩子都有,返回左右孩子最小深度+1;都没有,返回1 1 class Solut 阅读全文
posted @ 2018-10-20 16:30 adminyzz 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 107. Binary Tree Level Order Traversal II 将二叉树按层转化成列表,自底向上排列 按照每层进行处理,当层数据转化为列表a,下层节点存入列表b;每层处理完,处理列表b;最后反转列表。 1 class Solution: 2 def levelOrderBotto 阅读全文
posted @ 2018-10-19 16:41 adminyzz 阅读(80) 评论(0) 推荐(0) 编辑
摘要: Tree操作 # Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = None 100.Same Tree 阅读全文
posted @ 2018-10-18 16:48 adminyzz 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 38. Count and Say 递归算法 1 class Solution: 2 def handleN(self,l): 3 key = '' 4 tag = 0 5 result = '' 6 7 key = l[0] 8 for i in l: 9 if i == key: 10 tag 阅读全文
posted @ 2018-10-16 17:22 adminyzz 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 1 、从排序数组中删除重复项 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。 备注:是一个排序数组 1 class Solution: 2 def remo 阅读全文
posted @ 2018-05-08 23:28 adminyzz 阅读(144) 评论(0) 推荐(0) 编辑