上一页 1 2 3 4 5 6 7 8 9 ··· 51 下一页
摘要: 代码一:暴力超时了。 class Solution(object): # 暴力超时 def dailyTemperatures(self, T): """ :type T: List[int] :rtype: List[int] """ if not T: return [] res = [] fo 阅读全文
posted @ 2020-09-30 15:33 人间烟火地三鲜 阅读(126) 评论(0) 推荐(0)
摘要: 前天有个需求:把手头一张图片镜像翻转一下,奈何好多在线网站处理后有水印,于是写了几行代码可以处理。 """ 图像翻转的代码。 """ import cv2 # 定义读取图片的路径 img_dir = "photo.jpg" # 定义存储结果图片的路径 save_dir = "" img = cv2. 阅读全文
posted @ 2020-09-30 15:29 人间烟火地三鲜 阅读(165) 评论(0) 推荐(0)
摘要: 代码一 class Solution(object): # 思路:用前序式DFS,从root到叶子。 def binaryTreePaths(self, root): """ :type root: TreeNode :rtype: List[str] """ if not root: return 阅读全文
posted @ 2020-09-30 15:25 人间烟火地三鲜 阅读(125) 评论(0) 推荐(0)
摘要: class Solution(object): def minReorder(self, n, connections): """ :type n: int :type connections: List[List[int]] :rtype: int """ # 记录所有点的出、入度:0表示入度,1 阅读全文
posted @ 2020-09-30 15:21 人间烟火地三鲜 阅读(157) 评论(0) 推荐(0)
摘要: class Solution(object): # 思路:BST的中序遍历应该是一个有序序列 def isValidBST(self, root): """ :type root: TreeNode :rtype: bool """ if not root: return True midList 阅读全文
posted @ 2020-09-30 15:17 人间烟火地三鲜 阅读(133) 评论(0) 推荐(0)
摘要: class Solution(object): def findSecondMinimumValue(self, root): """ :type root: TreeNode :rtype: int """ if not root: return -1 temp = [] stack = [roo 阅读全文
posted @ 2020-09-30 15:15 人间烟火地三鲜 阅读(106) 评论(0) 推荐(0)
摘要: class Solution(object): def isUnivalTree(self, root): """ :type root: TreeNode :rtype: bool """ if not root: return True return self.dfs(root) def dfs 阅读全文
posted @ 2020-09-30 15:13 人间烟火地三鲜 阅读(77) 评论(0) 推荐(0)
摘要: class Solution(object): # 思路: # 先把句子按空格分成单词; # 遍历每个单词中的字符,查看是否是词根,是则替换并遍历下一个单词。 def replaceWords(self, dictionary, sentence): """ :type dictionary: Li 阅读全文
posted @ 2020-09-30 15:11 人间烟火地三鲜 阅读(142) 评论(0) 推荐(0)
摘要: 一、数学法思路:题中说其他元素均出现三次。 class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ return (3 * sum(list(set(nums))) 阅读全文
posted @ 2020-09-30 15:08 人间烟火地三鲜 阅读(189) 评论(0) 推荐(0)
摘要: class Solution(object): def singleNumbers(self, nums): """ :type nums: List[int] :rtype: List[int] """ nums.sort() res = [] # 特判:处理第一个和最后一个元素 if nums[ 阅读全文
posted @ 2020-09-30 15:03 人间烟火地三鲜 阅读(127) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 ··· 51 下一页