문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
def solution(dirs):
x,y = 0,0
next_x,next_y = 0,0
answer = set()
dir_dict = {"U":[0,1],
"D":[0,-1],
"R":[1,0],
"L":[-1,0]
}
for i in dirs:
for j in dir_dict:
if i == j:
next_x = x+dir_dict[i][0]
next_y = y+dir_dict[i][1]
if (-5<=next_x<=5) and (-5<=next_y<=5):
answer.add(((x,y),(next_x,next_y)))
answer.add(((next_x,next_y),(x,y)))
x,y = next_x, next_y
return len(answer)//2
'문제 풀이 > Programmers' 카테고리의 다른 글
[Programmers/Python] Lv1. 체육복 (2) | 2024.10.01 |
---|---|
[Programmers/Python] Lv1. 개인정보 수집 유효기간 (0) | 2024.09.28 |
[Programmers/Python] Lv2. 행렬의 곱셈 (0) | 2024.06.27 |
[Programmers/Python] Lv1. 실패율 (0) | 2024.06.10 |
[Programmers/Python] Lv1. 모의고사 (0) | 2024.06.07 |
댓글