摘要:        
class MagicDictionary(object): def __init__(self): """ Initialize your data structure here. """ self.mydict = {} def buildDict(self, dictionary): """     阅读全文
posted @ 2020-11-23 16:09
人间烟火地三鲜
阅读(102)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class Solution(object): def displayTable(self, orders): """ :type orders: List[List[str]] :rtype: List[List[str]] """ # 返回值 ans = [] # 第一趟遍历,listFood统    阅读全文
posted @ 2020-11-23 16:08
人间烟火地三鲜
阅读(119)
评论(0)
推荐(1)
        
            
        
        
摘要:        
class Solution(object): def numRabbits(self, answers): """ :type answers: List[int] :rtype: int """ if not answers: return 0 mydict = {} for item in a    阅读全文
posted @ 2020-11-23 16:06
人间烟火地三鲜
阅读(134)
评论(0)
推荐(0)
        
            
        
        
摘要:        
思路:将单词拆分出来的字符作为dict的key即可。 注意:python中key不能是list,需要转成tuple类型。 class Solution(object): def groupAnagrams(self, strs): """ :type strs: List[str] :rtype:     阅读全文
posted @ 2020-11-23 16:04
人间烟火地三鲜
阅读(94)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class Solution(object): def topKFrequent(self, words, k): """ :type words: List[str] :type k: int :rtype: List[str] """ # 用字典统计每个单词的数量 mydict = {} for    阅读全文
posted @ 2020-11-23 16:02
人间烟火地三鲜
阅读(81)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class FindElements(object): def getFolderNames(self, names): """ :type names: List[str] :rtype: List[str] """ mydict = {} res = [] for item in names:     阅读全文
posted @ 2020-11-23 16:01
人间烟火地三鲜
阅读(153)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class FindElements(object): # treeNode.left.val == 2 * x + 1 # treeNode.right.val == 2 * x + 2 def __init__(self, root): """ :type root: TreeNode """     阅读全文
posted @ 2020-11-23 15:59
人间烟火地三鲜
阅读(95)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class Solution(object): def __init__(self): self.mydict = {} # 1、dfs求每个节点的子树和,并用字典统计 # 2、遍历字典,按values域的大小降序排:mylist = sorted(mydict.items(), key = lam    阅读全文
posted @ 2020-11-23 15:56
人间烟火地三鲜
阅读(127)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class Solution(object): def largestValsFromLabels(self, values, labels, num_wanted, use_limit): """ :type values: List[int] :type labels: List[int] :t    阅读全文
posted @ 2020-11-23 15:54
人间烟火地三鲜
阅读(111)
评论(0)
推荐(0)
        
            
        
        
摘要:        
代码思路:横纵坐标的平方和,放到新list中,然后将新list升序排,取前K个即可。 class Solution(object): def kClosest(self, points, K): """ :type points: List[List[int]] :type K: int :rtyp    阅读全文
posted @ 2020-11-23 15:52
人间烟火地三鲜
阅读(121)
评论(0)
推荐(0)
        

 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号