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+ from typing import List
2+
3+ class Solution :
4+ def containsDuplicate (self , nums : List [int ]) -> bool :
5+ stack_list = []
6+ for i , n in enumerate (nums [:- 1 ]):
7+ stack_list .append (n )
8+ if nums [i + 1 ] in stack_list :
9+ return True
10+ else :
11+ if i == len (nums [:- 2 ]):
12+ return False
13+ continue
14+
Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+ class Solution :
4+ def topKFrequent (self , nums : List [int ], k : int ) -> List [int ]:
5+ nums_dict = {}
6+ for n in nums :
7+ if n not in nums_dict .keys ():
8+ nums_dict [n ] = 1
9+ else :
10+ nums_dict [n ] += 1
11+
12+ frequent_rank = sorted (nums_dict .items (), key = lambda item :item [1 ], reverse = True )
13+ return [frequent_rank [j ][0 ] for j in range (k )]
14+
Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+ class Solution :
4+ def twoSum (self , nums : List [int ], target : int ) -> List [int ]:
5+ for i , v in enumerate (nums ):
6+ second_value = target - v
7+
8+ if second_value in nums [i + 1 :]:
9+ return [i , nums [i + 1 :].index (second_value ) + i + 1 ]
10+
You can’t perform that action at this time.
0 commit comments