Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- burpsuite
- Python
- MySQL
- kubectl
- Review
- python #tkinter
- PY
- HTTP
- docker
- web
- NASA
- SQL
- datagrip
- Dictionary
- 오라클
- kubernetes
- URL
- Container
- Vagrant
- method
- VM
- kuberenetes
Archives
- Today
- Total
Deer
프로그래머스_키패드 누르기 python 본문
https://programmers.co.kr/learn/courses/30/lessons/67256
코딩테스트 연습 - 키패드 누르기
[1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5] "right" "LRLLLRLLRRL" [7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2] "left" "LRLLRRLLLRR" [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] "right" "LLRLLRLLRL"
programmers.co.kr
def solution(numbers, hand):
answer = ''
tempL = 10
tempR = 12
for num in numbers:
if num in [1,4,7]:
answer += 'L'
tempL = num
elif num in [3,6,9]:
answer += 'R'
tempR = num
else:
if num == 0:
num = 11
distL = (abs(tempL-num)//3)+(abs(tempL-num)%3)
distR = (abs(tempR-num)//3)+(abs(tempR-num)%3)
if distL == distR:
if hand == 'right':
answer += 'R'
tempR = num
else:
answer += 'L'
tempL = num
elif distL > distR:
answer += 'R'
tempR = num
else:
answer += 'L'
tempL = num
return answer
0을 11로 처리하는걸 놓쳤다
숫자들 거리 관계 알아내는 데 한참 걸렸다. 이런게 기본 지식인가... 지능으로 해결해야 하는건가 난 어려웠는데
IQ 측정 다시 해보고 싶다
'SW 공부 > python' 카테고리의 다른 글
string (0) | 2021.07.02 |
---|---|
useful functions: gcd / lcm / is_prime (0) | 2021.07.02 |
python 문법 6: 예외처리 (0) | 2020.09.08 |
python 문법 5 : 클래스 (0) | 2020.09.08 |
python 문법 4: 함수, 파일 입출력 (0) | 2020.09.08 |
Comments