File tree Expand file tree Collapse file tree 5 files changed +72
-0
lines changed
longest-consecutive-sequence Expand file tree Collapse file tree 5 files changed +72
-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+ return len (list (set (nums ))) != len (nums )
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def rob (self , nums : List [int ]) -> int :
3+ result = list (nums )
4+
5+ for i , data in enumerate (result ):
6+ if i <= 1 :
7+ continue
8+
9+ stolen_money = result [i ]
10+ before_house_money = result [i - 1 ]
11+
12+ for j in range (i - 1 ):
13+ if result [i ] + result [j ] > stolen_money :
14+ stolen_money = result [i ] + result [j ]
15+
16+ result [i ] = max (before_house_money , stolen_money )
17+
18+ return max (result )
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def longestConsecutive (self , nums : List [int ]) -> int :
3+ if len (nums ) <= 1 :
4+ return len (nums )
5+
6+ result = [1 ] * len (nums )
7+
8+ # ์ค๋ณต ์ ๊ฑฐ ํ ์ ๋ ฌ
9+ nums = sorted (list (set (nums )))
10+
11+ # ์ฐ์๋ ์ซ์ ์ฐพ๊ธฐ
12+ for i in range (1 , len (nums )):
13+ if nums [i ] - 1 == nums [i - 1 ]:
14+ result [i ] = result [i - 1 ] + 1
15+
16+ return max (result )
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+ my_dict = {}
4+ result = []
5+ temp_list = []
6+
7+ # ๋์
๋๋ฆฌ ์์ฑ
8+ for data in nums :
9+ if data not in my_dict .keys ():
10+ my_dict [data ] = 0
11+ my_dict [data ] = my_dict [data ] + 1
12+
13+ # ๋์
๋๋ฆฌ๋ฅผ ๋ฆฌ์คํธ๋ก ๋ณํ
14+ for data in my_dict .keys ():
15+ temp_list .append ([data , my_dict [data ]])
16+
17+ # ๋น๋์๋ฅผ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ
18+ temp_list .sort (key = lambda a : a [1 ],reverse = True )
19+
20+ # ์์ k๊ฐ ์์ ์ถ์ถ
21+ for i in range (k ):
22+ result .append (temp_list [i ][0 ])
23+
24+ return result
Original file line number Diff line number Diff line change 1+ class Solution :
2+
3+ def twoSum (self , nums : List [int ], target : int ) -> List [int ]:
4+ my_dict = {}
5+
6+ for i , data in enumerate (nums ):
7+ remaining = target - data
8+ if remaining not in my_dict :
9+ my_dict [data ] = i
10+ else :
11+ return [my_dict [remaining ], i ]
You canโt perform that action at this time.
0 commit comments