Algorithm

Algorithm/Programmers

[Lv.3] 길 찾기 게임

import java.util.*; class Solution { static List preResult=new ArrayList(); static List postResult=new ArrayList(); static List pointList=new ArrayList(); public int[][] solution(int[][] nodeinfo) { for (int i = 0; i < nodeinfo.length; i++) { int[] ints = nodeinfo[i]; pointList.add(new Point(ints[0], ints[1], i + 1)); } Collections.sort(pointList); Point root= pointList.get(0); for (int i = 1; i..

Algorithm/Programmers

[Lv.3] [1차] 셔틀버스- JAVA

import java.util.*; class Solution { public String solution(int n, int t, int m, String[] timetable) { String answer = ""; int startMin=9*60; int leaveMin=startMin+t*(n-1); List timeList=new ArrayList(); for (String s : timetable) { String[] split = s.split(":"); int time = Integer.parseInt(split[0])*60; time+=Integer.parseInt(split[1]); //마지막 차 출발 시간 이후에 줄을 서는 경우 경쟁대상이 아니다. if(time>leaveMin) co..

Algorithm/Programmers

[Lv.3] 불량 사용자

import java.util.*; import java.util.stream.Collectors; class Solution { static Set result=new HashSet(); static String[] users; static String[] bans; public int solution(String[] user_id, String[] banned_id) { users=user_id.clone(); bans=banned_id.clone(); dfs(0,new HashSet()); return result.size(); } public boolean checkBanned(String target, String banned) { if(target.length()!=banned.length()..

Algorithm/Programmers

[Lv.3] 스티커 모으기(2)

class Solution { static int size; static int maxSum; static boolean[] isTore; static boolean[] isNotPossible; static int[] stickers; public int solution(int sticker[]) { int answer = 0; if(sticker.length==1) return sticker[0]; if(sticker.length==2) return Math.max(sticker[0],sticker[1]); int[][] dp=new int[sticker.length+1][2]; dp[0][0]=-99999; dp[0][1]=sticker[0]; dp[1][0]=sticker[0]; dp[1][1]=..

Algorithm/Programmers

[Lv.3] 기지국 설치

import java.util.Arrays; class Solution { public int solution(int n, int[] stations, int w) { int answer = 0; Arrays.sort(stations); int startPoint=1; int coverage=2*w+1; for (int i=0;i=startPoint){ int blockDis=stations[i]-w-startPoint; answer+=blockDis/coverage+1; if(blockDis%coverage==0) answer--; } startPoint=stations[i]+w+1; if(startPoint>n) break; } if(startPoint

Algorithm/Programmers

[Lv.3] 숫자 게임

import java.util.Arrays; import java.util.stream.Collectors; class Solution { public int solution(int[] A, int[] B) { int answer = 0; Arrays.sort(A); Arrays.sort(B); int searchIndex=-1; boolean endFlag=false; for (int i : A) { while (true){ searchIndex++; if(searchIndex>=B.length){ endFlag=true; break; } if(B[searchIndex]>i){ //현재 A가 가진 가장 낮은 패에 대해서 가장 낮은패로 승리하기 answer++; break; } } if(endFlag) ..

Algorithm

자바 자바

코테를 보든 코딩을 하든 알고 있어야 하는 자바 상식 정리 Arrays.fill(arr, value) : arr을 value값으로 초기화 한다. list.stream().mapToInt(i→i).toArray() : Collection(list)를 array로 변환 한다. 큐에 데이터를 넣는 메소드로는 add와 offer가 있는데, add의 경우 성공시 true를 반환하고 실패시 예외(IllegalStateException)를 던지고 offer의 경우 성공시 value 실패시 false를 반환한다. 클래스 equals, hash code 정의 class TMP{ int a,b; @Override public boolean equals(Object o) { if (this == o) return true;..

Algorithm/Programmers

[Lv.3] 광고 삽입

93.5/100 (10,11번 실패) class Solution { public String solution(String play_time, String adv_time, String[] logs) { //그냥 play == adv면 바로 리턴 if(play_time.equals(adv_time)){ return "00:00:00"; } String answer = ""; String[] playTime = play_time.split(":"); int playHour=Integer.parseInt(playTime[0]); int playMinute=Integer.parseInt(playTime[1]); int playSecond=Integer.parseInt(playTime[2]); String[] a..

시롱시롱
'Algorithm' 카테고리의 글 목록 (9 Page)