Skip to content

Commit 895165f

Browse files
authored
Merge pull request DaleStudy#654 from heypaprika/main
[croucs] WEEK 1
2 parents 6e112ea + 188db98 commit 895165f

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

โ€Žcontains-duplicate/heypaprika.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Big-O ์˜ˆ์ƒ : O(n)
2+
class Solution:
3+
def containsDuplicate(self, nums: List[int]) -> bool:
4+
num_dict = {}
5+
for num in nums:
6+
if num in num_dict:
7+
return True
8+
else:
9+
num_dict[num] = 1
10+
return False
11+

โ€Žhouse-robber/heypaprika.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Big-O ์˜ˆ์ƒ : O(n)
2+
class Solution:
3+
def rob(self, nums: List[int]) -> int:
4+
a = [0] * len(nums)
5+
6+
if len(nums) == 1:
7+
return nums[0]
8+
elif len(nums) == 2:
9+
return max(nums[0], nums[1])
10+
11+
a[0] = nums[0]
12+
a[1] = nums[1]
13+
a[2] = max(a[0] + nums[2], a[1])
14+
15+
for i in range(3, len(nums)):
16+
a[i] = max(a[i-3], a[i-2]) + nums[i]
17+
18+
return max(a)
19+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Big-O ์˜ˆ์ƒ : O(nlog(n))
2+
class Solution:
3+
def longestConsecutive(self, nums: List[int]) -> int:
4+
nums = sorted(list(set(nums)))
5+
if len(nums) == 0:
6+
return 0
7+
elif len(nums) == 1:
8+
return 1
9+
cur_long = 1
10+
longest = 1
11+
for i, num in enumerate(nums):
12+
if i == 0:
13+
continue
14+
else:
15+
if nums[i-1] + 1 == nums[i]:
16+
cur_long += 1
17+
if longest < cur_long:
18+
longest = cur_long
19+
else:
20+
cur_long = 1
21+
return longest
22+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Big-O ์˜ˆ์ƒ : O(nlog(n))
2+
import heapq
3+
class Solution:
4+
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
5+
6+
num_dict = {}
7+
for num in nums:
8+
num_dict[num] = num_dict.get(num, 0) + 1
9+
heap = []
10+
for k_, v in num_dict.items():
11+
heapq.heappush(heap, [-v, k_])
12+
ans = []
13+
for i in range(k):
14+
ans.append(heapq.heappop(heap)[1])
15+
return ans
16+

โ€Žvalid-palindrome/heypaprika.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Big-O ์˜ˆ์ƒ : O(n)
2+
class Solution:
3+
def isPalindrome(self, s: str) -> bool:
4+
s = "".join(s.lower().split(" "))
5+
new_s = ""
6+
for item in s:
7+
if (ord("a") <= ord(item) <= ord("z")) or (ord("0") <= ord(item) <= ord("9")):
8+
new_s += item
9+
output = True
10+
new_s_2 = new_s[::-1]
11+
return new_s_2 == new_s
12+
return output
13+

0 commit comments

Comments
ย (0)