File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution (object ):
2+ def containsDuplicate (self , nums ):
3+ return len (set (nums ))!= len (nums )
Original file line number Diff line number Diff line change 1+ class Solution (object ):
2+ def topKFrequent (self , nums , k ):
3+ """
4+ :type nums: List[int]
5+ :type k: int
6+ :rtype: List[int]
7+ """
8+ freq = {}
9+ for n in nums :
10+ freq [n ] = freq .get (n , 0 ) + 1
11+
12+ buckets = [[] for _ in range (len (nums ) + 1 )]
13+ for num , count in freq .items ():
14+ buckets [count ].append (num )
15+
16+ result = []
17+ for count in range (len (nums ), 0 , - 1 ):
18+ for num in buckets [count ]:
19+ result .append (num )
20+ if len (result ) == k :
21+ return result
Original file line number Diff line number Diff line change 1+ class Solution (object ):
2+ def twoSum (self , nums , target ):
3+ for i in range (len (nums )):
4+ for j in range (i + 1 , len (nums )):
5+ if nums [i ] + nums [j ] == target :
6+ return [i , j ]
You can’t perform that action at this time.
0 commit comments