废纸的修炼之旅

看完文章点个赞吧 秋梨膏!!!

心情不好 刷题解闷。 题目描述 我的解法[复杂度太高 过不了的] class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: res = list(set(nums)) res.sort(key = lambda x:nums.count(...

发布 0 条评论

题目描述 我的解法[递归] # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def lowest...

发布 0 条评论

题目描述 我的解法 class Solution: def generate(self, numRows: int) -> List[List[int]]: res = [[1]*i for i in range(1,numRows+1)] for i in range(2,numRows): for j in range(1,i): ...

发布 0 条评论

题目描述 我的解法 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None from queue import Queue class Soluti...

发布 0 条评论

题目描述 我的解法 class Solution: def wordPattern(self, pattern: str, str: str) -> bool: if not str or not pattern: return False arr = str.split(" ") if len(arr)!= len(pattern)...

发布 0 条评论

题目描述 我的解法 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None from queue import Queue class Soluti...

发布 0 条评论

题目描述 我的解法 from collections import defaultdict class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: flag1 = defaultdict(bool) flag2 = defaultdict(bool) ...

发布 0 条评论

题目描述 解法 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None from collections import defaultdict class Solution: def deleteDu...

发布 0 条评论

题目描述 解法 class Solution: def minPathSum(self, grid: List[List[int]]) -> int: m = len(grid) if not m: return NULL n = len(grid[0]) dp = [[0]*n for i in range(m)] ...

发布 0 条评论

题目描述 解法 # class Solution: # def countBits(self, num: int) -> List[int]: # res = [] # for i in range(num+1): # temp = bin(i)[2:] # res.append(temp.count('1')) # ...

发布 0 条评论