java
백준 숨바꼭질(1697)
백준 숨바꼭질 풀이 bfs를 돌려서 깊이를 세어서 중복되는 위치의 수와 가장 낮은 위치를 출력해 주기만 하면되는 전형적인 그래프 문제 첫 제출은 2차원 배열을 사용해서 그런지 메모리 초과가 나왔는데 ArrayList로 해결 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static int depth[]; public static boolean visited[]; public static ArrayList map = new ArrayList(); public static int max; public sta..

프로그래머스 1차 다트 게임
프로그래머스 1차 다트 게임 내가 푼 풀이 import java.util.*; class Solution { public static int solution(String dartResult) { int answer = 0; int score = 0; int idx = 0; ArrayList list = new ArrayList(); for(int i=0; i= '0' && c 1) list.set(idx-2,list.get(idx-2)*2); list.set(idx-1,list.get(idx-1)*2); }else if(c == '#'){ list.set(idx-1,-list.get(idx-1)); } } for(int num : list) answer+=num; return answer; } }

프로그래머스 카카오 프렌즈 컬러링 북
프로그래머스 카카오 프렌즈 컬러링 북 풀이 bfs를 이용하여 해결 소요 시간 약 20분 class Pos{ public int x; public int y; public Pos(int y, int x){ this.y = y; this.x = x; } } class Solution { int dx[] = {0, 0, -1, 1}; // 상 하 좌 우 int dy[] = {-1, 1, 0, 0}; boolean visited[][]; PriorityQueue pq = new PriorityQueue(Collections.reverseOrder()); public int[] solution(int m, int n, int[][] picture) { int numberOfArea = 0; int maxSizeO..

프로그래머스 게임 맵 최단 거리
프로그래머스 게임 맵 최단거리 풀이 시작점을 기준으로 bfs 돌려서 큐에 넣을 때마다 이전거리 + 1씩 해줘서 넣어준다. 도착지점 거리를 리턴해준다 내가 푼 풀이 import java.util.*; class Pos{ int x; int y; public Pos(int y, int x) { this.y = y; this.x = x;} } class Solution { static int dx[] = {0, 0, -1, 1}; static int dy[] = {-1, 1, 0, 0}; static int visited[][]; public int solution(int[][] maps) { return bfs(maps,new Pos(0,0)); } public static int bfs(int[][] ma..