File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution :
2+ def containsDuplicate (self , nums : List [int ]) -> bool :
3+ if len (nums ) >= 1 and len (nums ) <= 100000 :
4+ for i in range (0 , len (nums )):
5+ src = nums [i ]
6+ for j in range (i + 1 , len (nums )):
7+ if src == nums [j ]:
8+ return True
9+ return False
10+ return False
11+
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def topKFrequent (self , nums : List [int ], k : int ) -> List [int ]:
3+ value_dict = {}
4+
5+ for num in nums :
6+ if num in value_dict :
7+ value_dict [num ] += 1
8+ else :
9+ value_dict [num ] = 1
10+
11+ sorted_items = sorted (value_dict .items (), key = lambda x : x [1 ], reverse = True )
12+
13+ return [key for key , value in sorted_items [:k ]]
14+
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def twoSum (self , nums : List [int ], target : int ) -> List [int ]:
3+ result = []
4+ if len (nums ) >= 2 and len (nums ) <= 1e4 :
5+ for idx1 , i in enumerate (nums ):
6+ num1 = i
7+ for idx2 in range (idx1 + 1 , len (nums )):
8+ num2 = nums [idx2 ]
9+ if ((num1 + num2 ) == target ):
10+ result .append (idx1 )
11+ result .append (idx2 )
12+ return result
13+
You can’t perform that action at this time.
0 commit comments