[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ผ๊ฐ ๋ฌํฝ์ด
1. ๋ฌธ์ : Link
์ผ๊ฐํ์ผ๋ก ๋์๊ฐ๋ฉด์ ์ซ์๋ฅผ ์ฑ์๋ฃ๋ ์ผ๊ฐ๋ฌํฝ์ด ์์ฑํ๋ ๋ฌธ์
2. ํ์ด
๋จผ์ ์ผ๊ฐ ๋ฌํฝ์ด์ ๊ป๋ฐ๊ธฐ๋ฅผ ๋ง๋ค์ด์ค๋ค.
๋ฐ๋ณต๋ฌธ์ ํตํด ํ์ ํ๋ฉด์ ๊ฐ์ ๋์ ํด์ค๋ค.
3. ์ฝ๋
def solution(n):
res = [[0] * n for _ in range(n)]
answer = []
x, y = -1, 0
num = 1
for i in range(n):
for j in range(i, n):
#down
if i % 3 == 0:
x += 1
#right
elif i % 3 == 1:
y += 1
#up
elif i % 3 == 2:
x -= 1
y -= 1
#์ ์ฅ
res[x][y] = num
num += 1
for i in res:
for j in i:
if j != 0:
answer.append(j)
return answer
* ์ฐธ๊ณ ) ์คํฌํธ๋ฆฌ for-esle๋ฌธ
'๐ป Coding Problems Solving > Array | String | Loop' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์์ ๋์งํ (0) | 2022.04.21 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 [1์ฐจ] ์บ์ (0) | 2022.04.19 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 2๊ฐ ์ดํ๋ก ๋ค๋ฅธ ๋นํธ (0) | 2022.04.18 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ํํ (0) | 2022.04.12 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 H-Index (0) | 2022.04.11 |
์ต๊ทผ๋๊ธ