Search
Duplicate

공원 산책

문제 설명 및 제한사항

아이디어 및 해결 방법

코드

def is_valid(r, c, park): return (0 <= r <= len(park) - 1) and (0 <= c <= len(park[0]) - 1) def solution(park, routes): found = False for r, row in enumerate(park): for c, char in enumerate(row): if char == 'S': found = True break if found: break for route in routes: op, n = route.split() n = int(n) if op == 'E' and is_valid(r, c+n, park): if all(char != 'X' for char in [park[r][c+i] for i in range(1, n+1)]): c += n elif op == 'S' and is_valid(r+n, c, park): if all(char != 'X' for char in [park[r+i][c] for i in range(1, n+1)]): r += n elif op == 'W' and is_valid(r, c-n, park): if all(char != 'X' for char in [park[r][c-i] for i in range(1, n+1)]): c -= n elif op == 'N' and is_valid(r-n, c, park): if all(char != 'X' for char in [park[r-i][c] for i in range(1, n+1)]): r -= n return r, c
Python
복사

출처

프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges