Skip to content

Commit bf1c3a8

Browse files
authored
Merge pull request #1634 from shinsj4653/main
[shinsj4653] Week 14 Solutions
2 parents 63753a2 + 4a759e7 commit bf1c3a8

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+

counting-bits/shinsj4653.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
n: int
5+
# Outputs
6+
7+
ans: arr
8+
길이: n + 1
9+
10+
ans내 각 원소들 : ans[i]: i의 이진법에서 1의 개수
11+
12+
# Constraints
13+
0 <= n <= 10^5
14+
15+
# Ideas
16+
2중 for문 이면 안됨
17+
18+
[회고]
19+
dp를 활용한 풀이도 같이 알아두자
20+
"""
21+
22+
# 내 풀이
23+
class Solution:
24+
def countBits(self, n: int) -> List[int]:
25+
26+
ans = []
27+
28+
for i in range(n + 1):
29+
if i == 0 or i == 1:
30+
ans.append(i)
31+
continue
32+
33+
num = i
34+
cnt = 0
35+
while num > 0:
36+
num, n = num // 2, num % 2
37+
if n == 1:
38+
cnt += 1
39+
40+
ans.append(cnt)
41+
42+
return ans
43+
44+
# 해설
45+
class Solution:
46+
def countBits(self, n: int) -> List[int]:
47+
dp = [0] * (n + 1)
48+
for num in range(1, n + 1):
49+
dp[num] = dp[num // 2] + (num % 2)
50+
return dp
51+
52+

house-robber-ii/shinsj4653.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+

meeting-rooms-ii/shinsj4653.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+

word-search-ii/shinsj4653.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+

0 commit comments

Comments
 (0)