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

Commit ecd1bbb

Browse files
authored
Merge pull request #398 from boostcamp-ai-tech-4/humi-1212
[ํ›„๋ฏธ] 2021.12.11
2 parents 2a42d9d + d3319a5 commit ecd1bbb

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def solution(s):
2+
stack=[]
3+
for c in s:
4+
# stack์˜ ๋งˆ์ง€๋ง‰์ด๋ž‘ ํ˜„์žฌ ๋ฌธ์ž๊ฐ€ ๊ฐ™์œผ๋ฉด ์ œ๊ฑฐ
5+
if stack and c ==stack[-1]:
6+
stack.pop()
7+
else:
8+
stack.append(c)
9+
if len(stack)==0:
10+
return 1
11+
else:
12+
return 0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cnt=0
2+
3+
def dfs(graph,target,current_sum,idx):
4+
global cnt
5+
# index๊ฐ€ ๋๊นŒ์ง€ ๊ฐ”์„๋•Œ target์ด๋ž‘ ๊ฐ™์œผ๋ฉด cnt ++
6+
if idx==len(graph):
7+
if current_sum==target:
8+
cnt+=1
9+
return
10+
else:
11+
# ๋”ํ•˜๊ธฐ
12+
dfs(graph,target,current_sum+graph[idx],idx+1)
13+
# ๋นผ๊ธฐ
14+
dfs(graph,target,current_sum-graph[idx],idx+1)
15+
16+
def solution(numbers, target):
17+
# ๋ˆ„์ ํ•ฉ = 0 index = 0 ๋ถ€ํ„ฐ ์‹œ์ž‘
18+
dfs(numbers,target,0,0)
19+
20+
return cnt
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
def solution(rows, columns, queries):
2+
answer = []
3+
# ์ดˆ๊ธฐ ํ–‰๋ ฌ ์ดˆ๊ธฐํ™”
4+
mat = []
5+
cnt = 0
6+
for _ in range(rows):
7+
temp = []
8+
for _ in range(columns):
9+
cnt += 1
10+
temp.append(cnt)
11+
mat.append(temp)
12+
13+
for si,sj,ei,ej in queries:
14+
# index ๋งž์ถฐ์ฃผ๊ธฐ์œ„ํ•ด 1์”ฉ ๋นผ์คŒ
15+
si -= 1
16+
sj -= 1
17+
ei -= 1
18+
ej -= 1
19+
w = ej - sj
20+
h = ei - si
21+
# ๋‹ค์Œ ์ขŒํ‘œ์˜ ๋ฐฉํ–ฅ
22+
directions = [(0,1),(1,0),(0,-1),(-1,0)]
23+
idx = 0
24+
# ๋Œ๋ ค์•ผํ•˜๋Š” ๋ฐฐ์—ด? ์ง์‚ฌ๊ฐํ˜• ํ…Œ๋‘๋ฆฌ์˜ ๊ผญ์ง“์ ๋“ค
25+
corners = [w, w + h, 2 * w + h]
26+
# ์ดˆ๊ธฐ๊ฐ’ ์„ธํŒ…
27+
prev = mat[si][sj] # si, sj๊ฐ€ ์‹œ์ž‘์ 
28+
mat[si][sj] = mat[si+1][sj] # si, sj์—๋Š” ๋ฐ”๋กœ ๋ฐ‘์— ๊ฐ’์ด ๋“ค์–ด๊ฐ
29+
_min = prev # ์ตœ์†Œ ๊ฐ’ ์„ค์ •
30+
31+
for i in range((w + h) * 2 - 1):
32+
# ์ฝ”๋„ˆ์— ๋„๋‹ฌํ–ˆ์œผ๋ฉด ๋ฐฉํ–ฅ ๋ฐ”๊ฟ”์ฃผ๊ธฐ
33+
if i in corners:
34+
idx += 1
35+
# ์ƒˆ ์ขŒํ‘œ
36+
ni, nj = si + directions[idx][0], sj + directions[idx][1]
37+
temp = mat[ni][nj]
38+
mat[ni][nj] = prev
39+
prev = temp
40+
si, sj = ni,nj
41+
_min = min(_min,prev)
42+
answer.append(_min)
43+
return answer

0 commit comments

Comments
ย (0)