forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4.py
More file actions
28 lines (25 loc) ยท 847 Bytes
/
4.py
File metadata and controls
28 lines (25 loc) ยท 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# ์ฌ์ ์ ์ ๋ ฌ๋ ๋ฆฌ์คํธ A์ B ์ ์ธ
n, m = 3, 4
a = [1, 3, 5]
b = [2, 4, 6, 8]
# ๋ฆฌ์คํธ A์ B์ ๋ชจ๋ ์์๋ฅผ ๋ด์ ์ ์๋ ํฌ๊ธฐ์ ๊ฒฐ๊ณผ ๋ฆฌ์คํธ ์ด๊ธฐํ
result = [0] * (n + m)
i = 0
j = 0
k = 0
# ๋ชจ๋ ์์๊ฐ ๊ฒฐ๊ณผ ๋ฆฌ์คํธ์ ๋ด๊ธธ ๋๊น์ง ๋ฐ๋ณต
while i < n or j < m:
# ๋ฆฌ์คํธ B์ ๋ชจ๋ ์์๊ฐ ์ฒ๋ฆฌ๋์๊ฑฐ๋, ๋ฆฌ์คํธ A์ ์์๊ฐ ๋ ์์ ๋
if j >= m or (i < n and a[i] <= b[j]):
# ๋ฆฌ์คํธ A์ ์์๋ฅผ ๊ฒฐ๊ณผ ๋ฆฌ์คํธ๋ก ์ฎ๊ธฐ๊ธฐ
result[k] = a[i]
i += 1
# ๋ฆฌ์คํธ A์ ๋ชจ๋ ์์๊ฐ ์ฒ๋ฆฌ๋์๊ฑฐ๋, ๋ฆฌ์คํธ B์ ์์๊ฐ ๋ ์์ ๋
else:
# ๋ฆฌ์คํธ B์ ์์๋ฅผ ๊ฒฐ๊ณผ ๋ฆฌ์คํธ๋ก ์ฎ๊ธฐ๊ธฐ
result[k] = b[j]
j += 1
k += 1
# ๊ฒฐ๊ณผ ๋ฆฌ์คํธ ์ถ๋ ฅ
for i in result:
print(i, end=' ')