~๋ชฉ์ฐจ~
๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/67256
๋ฌธ์ ํด๊ฒฐ ํฌ์ธํธ
- ๊ฐ ํค๋ณด๋๋ง๋ค ๋ฒํธ๋ฅผ ๋ถ์ฌ '*', '#' ์ ๊ฐ๊ฐ 10, 11๋ฒ
- 1, 4, 7์ ์ผ์์ด 3, 6, 9๋ ์ค๋ฅธ์์ด ๊ฒฐ์ ๋ผ์ด ์์ผ๋ 2, 5, 8, 0์ ์ค๋ฅธ์์ธ์ง ์ผ์์ธ์ง ๊ฒฐ์ ํด์ผํจ
: ๊ทธ๋ฌ๋ฏ๋ก 2, 5, 7, 0 ์ผ๋ก๋ถํฐ ๋ค๋ฅธ ํค๋ณด๋๊น์ง์ ๊ฑฐ๋ฆฌ๋ฅผ ์ ์ฅํ keypad ๋์ ๋๋ฆฌ ์์ฑ
- ํ์ฌ ์ผ์, ์ค๋ฅธ์์ด ์์นํ ํค๋ณด๋ ์์น๋ฅผ ๋น๊ตํ์ฌ ๊ฐ๊น์ด ์ ๋๋ ์ต์ํ ์์ ๋ง๊ฒ ์ด๋์์ผ๊ฐ๋ฉฐ ๋์
์์ฑ ์ฝ๋
keypad = {2: [3, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4, 4],
5: [2, 2, 1, 2, 1, 0, 1, 2, 1, 2, 3, 3],
8: [1, 3, 2, 3, 2, 1, 2, 1, 0, 1, 2, 2],
0: [0, 4, 3, 4, 3, 2, 3, 2, 1, 2, 1, 1]}
def solution(numbers, hand):
hand = 'R' if hand == 'right' else 'L'
left = 10
right = 11
result = ''
for n in numbers:
if n in [1, 4, 7]:
result += 'L'
left = n
elif n in [3, 6, 9]:
result += 'R'
right = n
else:
if keypad[n][right] == keypad[n][left]:
result += hand
if hand == 'R':
right = n
else:
left = n
elif keypad[n][right] < keypad[n][left]:
result += 'R'
right = n
else:
result += 'L'
left = n
return result
๋์์ด ๋์ จ๋ค๋ฉด ์ข์์ ๋๋ฌ์ฃผ์ธ์๐
'๐๋ฌธ์ ํ์ด > ๐งฉProgrammers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ๋ด ๋ง์๋๋ก ์ ๋ ฌํ๊ธฐ (0) | 2023.05.05 |
---|---|
[JAVA] ํ๋ก๊ทธ๋๋จธ์ค ์ต์์ง์ฌ๊ฐํ (0) | 2023.05.05 |
[Python] ํ๋ก๊ทธ๋๋จธ์ค H-Index (0) | 2023.04.22 |
[Python] ํ๋ก๊ทธ๋๋จธ์ค ๊ฒ์ ๋งต ์ต๋จ๊ฑฐ๋ฆฌ | ํจ์จ์ฑ (2) | 2023.04.21 |
[Python] ํ๋ก๊ทธ๋๋จธ์ค ๋คํธ์ํฌ | BFS/DFS (0) | 2023.04.19 |