Skip to content

Commit 518d355

Browse files
committed
feat: add week 09 problems
1 parent 2544818 commit 518d355

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

linked-list-cycle/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+
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+
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+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
[문제풀이]
3+
# Inputs
4+
5+
# Outputs
6+
7+
# Constraints
8+
9+
# Ideas
10+
11+
[회고]
12+
13+
"""
14+
15+
16+
class Solution:
17+
def pacificAtlantic(heights):
18+
ret = []
19+
20+
dy = [-1, 0, 1, 0]
21+
dx = [0, 1, 0, -1]
22+
23+
n, m = len(heights), len(heights[0])
24+
25+
def isPacific(y, x): # pacific 도달 가능한지
26+
if y == 0 or (0 <= y < n and x == 0):
27+
return True
28+
29+
else:
30+
return False
31+
32+
def isAtlantic(y, x): # Atlantic 도달 가능한지
33+
if y == n - 1 or (0 <= y < n and x == m - 1):
34+
return True
35+
36+
else:
37+
return False
38+
39+
def inRange(y, x):
40+
if 0 <= y < n and 0 <= x < m:
41+
return True
42+
else:
43+
return False
44+
45+
v = [[False for _ in range(m)] for _ in range(n)]
46+
47+
def dfs(y, x, heights, v):
48+
if isPacific(y, x) and isAtlantic(y, x):
49+
return True
50+
51+
v[y][x] = True
52+
53+
for i in range(4):
54+
ny, nx = y + dy[i], x + dx[i]
55+
if inRange(ny, nx) and not v[ny][nx] and \
56+
heights[y][x] >= heights[ny][nx]:
57+
if dfs(ny, nx, heights, v):
58+
return True
59+
60+
v[y][x] = False
61+
return False
62+
63+
for i in range(n):
64+
for j in range(m):
65+
if dfs(i, j, heights, v):
66+
ret.append((i, j))
67+
68+
return ret
69+
70+
pacificAtlantic([[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]])
71+

sum-of-two-integers/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)