class Solution { static int endX,endY; public String solution(int n, int m, int x, int y, int r, int c, int k) { String answer = ""; //d -> l -> r -> u int height=Math.abs(r-x); int width=Math.abs(c-y); int sum=height+width; if(sum%2==1&&k%2!=1) return "impossible"; if(sum%2==0&&k%2!=0) return "impossible"; if(sum>k) return "impossible"; //빠른순으로 이동을 시도하고 되면 해당 경로로만 가는거 약간 그리디 느낌으로 해야될 듯 int left..
프로그래머스 표병합 문제를 풀며 유니온 파인드 알고리즘에 대해 처음 알았고 정리할 필요가 있다고 생각되어 정리하려고 한다. 쉽게 생각하면 Union은 말그대로 합집합 즉, 그룹을 합친다는 것을 의미하고 Find는 해당 그룹의 부모를 찾는 것을 의미한다. public static void union(int a, int b) { a = find(a); b = find(b); if(a != b) parent[b] = a; } A란 그룹과 B란 그룹이 있고 각각 부모가 a,b라면 Union(A,B)를 하게 되면 새로운 그룹 C가 생성되고 C=AUB가 되는 셈이다. 여기서 그룹의 부모는 a혹은 b가된다. 코드를 보면 알겠지만 a,b의 부모를 각각 찾은 후 두 부모가 같지 않다면 한쪽의 부모를 다른 한쪽의 부모로 ..
import java.util.ArrayList; import java.util.List; class Solution { static Point[][] points = new Point[51][51]; public String[] solution(String[] commands) { List answer=new ArrayList(); for (int i = 1; i
import java.util.ArrayList; import java.util.List; class Solution { public int solution(int[][] scores) { int answer = 0; int a=scores[0][0]; int b=scores[0][1]; List pointList=new ArrayList(); for (int i = 1; i a&&scores[i][1]>b) return -1; if(scores[i][0]
class Solution { public int solution(String[] lines) { int answer = 0; //overFlow? int[] msAcSum=new int[86400005]; int firstMs=99999999; int lastMs=0; for (String line : lines) { int time=0; String[] split = line.split(" "); String[] dates = split[1].split(":"); int hour=Integer.parseInt(dates[0]); time+=hour*60*60*1000; int min=Integer.parseInt(dates[1]); time+=min*60*1000; double secs = Doubl..