![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode腾讯
菜菜编程
这个作者很懒,什么都没留下…
展开
-
力扣腾讯反转链表
力扣反转链表通过迭代# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def reverseList(self, head: ListNode) -> ListNode: if head == None:原创 2021-01-05 13:15:59 · 136 阅读 · 0 评论 -
122. 买卖股票的最佳时机 II&&738. 单调递增的数字
买入股票的时机,就是后一天的价比今天的价格高才买入;卖出的条件是今天的价格比明天的价格低,卖出的同时也买入第二天的股票。class Solution: def maxProfit(self, prices: List[int]) -> int: ''' 在右数大于左数时选择右数买入,在左数卖出 ''' profit = 0 flag = True global i if len原创 2020-12-15 22:25:22 · 116 阅读 · 0 评论 -
查找二叉树的最大深度
查找二叉树的最大深度leetcode104,根据官方的方法有递归法和广度优先遍历;递归法,如图所示,广度优先遍历,设计数器每次读取一层(类似于二叉树的层次遍历)#递归法class Solution: def maxDepth(self, root): if root is None: return 0 else: left_height = self.maxDepth(root.left)原创 2020-12-14 21:05:50 · 467 阅读 · 0 评论 -
字母异位词分组
字母异位词分组Leetcode第49题下面是菜菜的想法与实现,采用了字典计数器来实现,比较费时间和内存吧(emmm)class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: if strs==[]:return [] res = [] # 输出结果 count = [] #计数器 for k in range(len(s原创 2020-12-14 15:39:10 · 69 阅读 · 0 评论