Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit 2a42d9d

Browse files
authored
Merge pull request #397 from boostcamp-ai-tech-4/penguin-1211
[ํŽญ๊ท„] 2021.12.11
2 parents c471484 + d8fb7b0 commit 2a42d9d

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def compress(s):
2+
stack = [s[0]]
3+
for i in range(1, len(s)):
4+
if stack and s[i] == stack[-1]:
5+
stack.pop()
6+
else:
7+
stack.append(s[i])
8+
return stack
9+
10+
11+
def solution(s):
12+
# ์••์ถ•์ด ๋˜๋ฉด
13+
if compress(s):
14+
return 0 # 0์„ ๋ฐ˜ํ™˜
15+
return 1 # ์•ˆ ๋˜๋ฉด 1์„ ๋ฐ˜ํ™˜
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def solution(numbers, target):
2+
n = len(numbers)
3+
count = 0
4+
for i in range(1 << n):
5+
total = 0
6+
for j in range(n):
7+
# ๋น„ํŠธ๊ฐ€ 1์ด๋ฉด
8+
if i & 1 << j:
9+
total += numbers[j] # ๋”ํ•ด์ค€๋‹ค
10+
# ๋น„ํŠธ๊ฐ€ 0์ด๋ฉด
11+
else:
12+
total -= numbers[j] # ๋นผ์ค€๋‹ค
13+
# ๊ฒฐ๊ณผ๊ฐ€ ํƒ€๊ฒŸ๊ณผ ์ผ์น˜ํ•˜๋ฉด
14+
if total == target:
15+
count += 1 # ์นด์šดํŠธ๋ฅผ +1 ํ•ด์ค€๋‹ค
16+
return count
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)]
2+
3+
4+
def solution(rows, columns, queries):
5+
matrix = [[j * columns + i for i in range(1, columns + 1)] for j in range(rows)]
6+
result = []
7+
for y1, x1, y2, x2 in queries:
8+
min_num = 10000 # ์ตœ์†Œ ์ˆซ์ž
9+
cy, cx, cd = y1 - 1, x1 - 1, 0 # ํ˜„์žฌ ์œ„์น˜(y, x)์™€ ์ด๋™ ๋ฐฉํ–ฅ
10+
new_matrix = [row[:] for row in matrix]
11+
# ๋ชจ๋“  ๋ฐฉํ–ฅ์„ ๋Œ ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต
12+
while cd < 4:
13+
min_num = min(min_num, matrix[cy][cx]) # ์ตœ์†Ÿ๊ฐ’ ๊ฐฑ์‹ 
14+
ny, nx = cy + dirs[cd][0], cx + dirs[cd][1] # ์ด๋™ํ•  ์œ„์น˜
15+
# ๋ฒ”์œ„์—์„œ ๋ฒ—์–ด๋‚˜๋ฉด
16+
if (ny < y1 - 1 or ny > y2 - 1) or (nx < x1 - 1 or nx > x2 - 1):
17+
cd += 1 # ๋ฐฉํ–ฅ์„ ๋ฐ”๊พผ๋‹ค
18+
continue
19+
new_matrix[ny][nx] = matrix[cy][cx]
20+
cy, cx = ny, nx
21+
matrix = new_matrix
22+
result.append(min_num)
23+
return result

0 commit comments

Comments
ย (0)