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
- 문제풀이
- 코딩테스트
- BFS
- 러닝일지
- 프로그래머스
- MySQL
- 건강
- dfs
- 백준
- SQL
- math
- oracle
- SWEA
- 문자열
- 자바
- priorityqueue
- 코테
- DP
- 문제해결
- 시뮬레이션
- binary search
- db
- Java
- 이분탐색
- greedy
- 투포인터
- 운동기록
- BOJ
- 알고리즘
- COS PRO
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.2 방문 길이 본문





[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/49994
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
class Solution {
int[] dy = {1,0,-1,0};
int[] dx = {0,1,0,-1};
public int solution(String dirs) {
int answer = 0;
boolean[][][] visit = new boolean[11][11][4];
int y = 5; int x = 5;
int d = 0;
for(char c : dirs.toCharArray()){
if(c=='U') d = 0;
if(c=='R') d = 1;
if(c=='D') d = 2;
if(c=='L') d = 3;
int ny = y + dy[d];
int nx = x + dx[d];
if(ny<0 || ny>=11 || nx<0 || nx>=11) continue;
if(!visit[ny][nx][d]){
visit[ny][nx][d] = true;
answer++;
}
visit[y][x][(d+2) % 4] = true;
y = ny; x = nx;
}
return answer;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] Lv.2 뒤에 있는 큰 수 찾기 (0) | 2025.10.16 |
|---|---|
| [프로그래머스] Lv.2 모음사전 (0) | 2025.10.16 |
| [프로그래머스] Lv.2 타겟 넘버 (0) | 2025.10.15 |
| [프로그래머스] Lv.2 롤케이크 자르기 (0) | 2025.10.15 |
| [프로그래머스] Lv.2 전화번호 목록 (0) | 2025.10.15 |