Algorithm/Programmers (11) 썸네일형 리스트형 [프로그래머스_SQL] 3월에 태어난 여성 회원 목록 출력하기 문제 풀이 중에 Oracle과 MySQL의 날짜 추출 방법이 다르다는 점을 알아냈습니다. MySQLSELECT MEMBER_ID, MEMBER_NAME, GENDER, DATE_FORMAT(DATE_OF_BIRTH, '%Y-%m-%d') as DATE_OF_BIRTHFROM MEMBER_PROFILEWHERE MONTH(DATE_OF_BIRTH) = '03' AND GENDER = 'W' AND TLNO IS NOT NULLORDER BY MEMBER_ID ASC;MySQL은 DATE_FORMAT을 이용하여 %Y-%m-%d와 같은 형식으로 추출합니다. OracleSELECT MEMBER_ID, MEMBER_NAME, GENDER, TO_CHAR(DATE_OF_BIRTH, 'YYYY-MM-DD') as.. [프로그래머스_JAVA_알고리즘] 완주하지 못한 선수 #해시 import java.util.HashMap;class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; HashMap hashmap = new HashMap(); for(String player : participant) hashmap.put(player, hashmap.getOrDefault(player, 0) +1); for(String player : completion) hashmap.put(player, hashmap.get(player) -1); .. [프로그래머스_JAVA_알고리즘] 디스크 컨트롤러 #힙 #우선순위 큐 PriorityQueue를 오름차순 정렬 후, 작업 시간이 짧은 순서대로 저장하는 로직을 구현합니다. import java.util.*;class Solution { public int solution(int[][] jobs) { int answer = 0; int endTime = 0; // 오름차순 정렬 Arrays.sort(jobs, (a, b) -> a[0] - b[0]); PriorityQueue priorityQueue = new PriorityQueue((a, b) -> a[1] - b[1]); // 작업의 소요시간이 짧은 것, 작업의 요청 시각이 빠른 것.. [프로그래머스_JAVA_알고리즘] 더 맵게 #힙 #우선순위 큐 힙 문제는 우선순위 큐 Priority Queue를 이용해서 풀 수 있습니다.import java.util.*;class Solution { public int solution(int[] scoville, int K) { int answer = 0; PriorityQueue priorityQueue = new PriorityQueue(); for(int s: scoville) priorityQueue.add(s); int num = priorityQueue.peek(); while(num = 2){ priorityQueue.add(priorityQueue.poll.. [프로그래머스_JAVA_알고리즘] 의상 #해시 HashMap을 이용해서 문제를 해결할 수 있습니다.import java.util.*;class Solution { public int solution(String[][] clothes) { HashMap hashmap = new HashMap(); for(String[] cloth : clothes){ String category = cloth[1]; // 의상의 종류를 추출 hashmap.put(category, hashmap.getOrDefault(category, 0) + 1); } int answer = 1; for(int count : hashmap.value.. [프로그래머스_JAVA_알고리즘] 문자열 정렬하기 (2) #정렬 Arrays.sort()를 이용해서 문제를 해결할 수 있습니다.import java.util.*;class Solution { public String solution(String my_string) { my_string = my_string.toLowerCase(); char[] chArr = my_string.toCharArray(); Arrays.sort(chArr); return new String(chArr); }} Arrays.sort() 메서드는 배열 타입만 받기 때문에 문자열을 바로 정렬할 수 없습니다. 예를 들어, String은 하나의 문자열 객체이기 때문에 Arrays.sort()에 바로 전달하면 오류가 발생합니다. 이를 해결.. [프로그래머스_JAVA_알고리즘] H-Index #정렬 Arrays.sort를 이용해서 정렬 후 최대값을 리턴할 수 있습니다.import java.util.*;class Solution { public int solution(int[] citations) { int answer = 0; Arrays.sort(citations); // 인용 수를 오름차순 정렬 for(int i = 0; i = h){ // 조건 확인: 인용 수가 h 이상인 논문이 h편 이상 answer = h; break; } } return answer; }} citations를 정렬하면 [0, 1, 3, 5, 6]이 됩니다.해당 논.. [프로그래머스_JAVA_알고리즘] 가장 큰 수 #정렬 Arrays.sort에 Comparator을 사용하여 구현할 수 있습니다.Comparator은 두 숫자 문자열의 조합을 비교하여 어느 조합이 더 큰지를 판단할 수 있습니다.import java.util.*;class Solution { public String solution(int[] numbers) { String answer = ""; String[] arr = new String[numbers.length]; for(int i = 0; i () { public int compare(String s1, String s2) { return (s2 + s1).compareTo(s1 + s2); .. 이전 1 2 다음 목록 더보기