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
- ssd
- 2단계
- test-helper
- 1단계
- 모두를 위한 딥러닝 강좌 시즌1
- AWS
- cs
- 구현
- SWEA
- MySQL
- 코드수행
- Object detection
- 머신러닝
- pytorch
- ubuntu
- 전산기초
- 3단계
- C++
- docker
- 프로그래머스
- Python
- CS231n
- 딥러닝
- 백준
- 파이썬
- 이것이 코딩테스트다 with 파이썬
- STL
- 그리디
- 자료구조 및 실습
- 실전알고리즘
Archives
- Today
- Total
곰퓨타의 SW 이야기
[프로그래머스 level2 방문길이] visited 활용하기 본문
해결해야하는 문제는 다음과 같았다.
https://programmers.co.kr/learn/courses/30/lessons/49994?language=python3
코딩테스트 연습 - 방문 길이
programmers.co.kr
코드가 효율적인 것 같지는 않지만, 이러한 아이디어를 바탕으로 작성한 풀이는 다음과 같다.
def check(pos_x,pos_y):
if pos_x<0 or pos_x>10 or pos_y<0 or pos_y>10 :
return False
return True
def solution(dirs):
count = 0
visited = []
pos_x = 5
pos_y = 5
for dir in dirs :
new_x, new_y = pos_x, pos_y
if dir == 'U':
new_x -= 1
elif dir == 'D':
new_x += 1
elif dir == 'R':
new_y += 1
else :
new_y -= 1
if check(new_x,new_y):
if [[pos_x,pos_y],[new_x,new_y]] not in visited:
visited.append([[pos_x,pos_y],[new_x,new_y]])
visited.append([[new_x,new_y],[pos_x,pos_y]])
count += 1
pos_x , pos_y = new_x, new_y
return count
'TIL > 프로그래머스' 카테고리의 다른 글
[프로그래머스 level2 중성화 여부 파악하기] case 활용하기2 (0) | 2021.06.14 |
---|---|
[프로그래머스 level2 NULL 처리하기] case 활용하기 (0) | 2021.06.14 |
[프로그래머스 level2 이름에 el이 들어가는 동물 찾기] like 사용하기 (0) | 2021.06.14 |
[프로그래머스 level2 루시와 엘라 찾기] or 사용하기 (0) | 2021.06.14 |
[프로그래머스 level2 2개 이하로 다른 비트] 규칙 찾기! (0) | 2021.06.13 |
Comments