programmers 60

[programmers] 다음 큰 숫자

문제https://school.programmers.co.kr/learn/courses/30/lessons/12911 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(int n) { int answer = 0; String str = Integer.toBinaryString(n); int cnt = 0; for (int i = 0; i n을 2진수로 변환한 뒤 1의 개수를 센다. 다음 n을 1씩 증가시키면서 2진수로 변환한 값의 1의 개수가 처음 n을 2진수로 변환했을 때 1의 개수와 일치하는지 확인한다. 일치할 때..

[programmers] 둘만의 암호

문제https://school.programmers.co.kr/learn/courses/30/lessons/155652 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public String solution(String s, String skip, int index) { String answer = ""; for (int i = 0; i 문자열 s를 탐색하며 각 문자를 index만큼 뒤의 알파벳으로 바꿔준다. 이때, z를 넘어가면 a로 돌아가게 하고, skip에 있는 알파벳이라면 제외한다. 최종 index만큼 뒤의 알파벳을 answer에 저장한 후 an..

[programmers] 기사단원의 무기

문제https://school.programmers.co.kr/learn/courses/30/lessons/136798 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(int number, int limit, int power) { int answer = 0; for (int i = 1; i limit) { answer += power; } else { answer += cnt; } } return answer; }} 1부터 number까지 각 숫자의 약수의 개수를 구한다. 약수의 개수가 limit..

[programmers] 혼자 놀기의 달인

문제https://school.programmers.co.kr/learn/courses/30/lessons/131130 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int solution(int[] cards) { int answer = 0; ArrayList list = new ArrayList(); for (int i = 0; i = 2) { answer = list.get(0) * list.get(1); } return answer; }} cards를 살펴보며 값이 -1이라면 이미 그룹에 속한..

[programmers] 달리기 경주

문제https://school.programmers.co.kr/learn/courses/30/lessons/178871 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public String[] solution(String[] players, String[] callings) { String[] answer = new String[players.length]; HashMap map = new HashMap(); HashMap rank = new HashMap(); for (int i = 0; i HashMap에 이름..

[programmers] 덧칠하기

문제https://school.programmers.co.kr/learn/courses/30/lessons/161989 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(int n, int m, int[] section) { int answer = 0; int end = 0; for (int i = 0; i section[i]) { continue; } end = section[i] + m; answer += 1; if (end > n) { break; } } return answer;..

[programmers] 과제 진행하기

문제https://school.programmers.co.kr/learn/courses/30/lessons/176962 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { static class Plan { private String name; private int start; private int playtime; public Plan(String name, int start, int playtime) { this.name = name; this.start = start; this.playtime = playt..

[programmers] 땅따먹기

문제https://school.programmers.co.kr/learn/courses/30/lessons/12913 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { int solution(int[][] land) { int answer = 0; int[][] sum = new int[land.length][4]; for (int i = 0; i 합을 구하기 위해 sum 배열을 선언한다. 첫 행은 land 값 그대로 저장한다. 다음 행부터 탐색하며 같은 열이 아닌 윗행과 합이 최댓값일 때를 찾아 저장한다. 최종 sum 배열의 마지막 행 중에서 최댓값을..

[programmers] 공원 산책

문제https://school.programmers.co.kr/learn/courses/30/lessons/172928 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int[] solution(String[] park, String[] routes) { int[] answer = new int[2]; char arr[][] = new char[park.length][park[0].length()]; int x = -1, y = -1; for (int i = 0; i = arr.length || arr[x + j][y] == 'X') { ..

[programmers] 무인도 여행

문제https://school.programmers.co.kr/learn/courses/30/lessons/154540 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int[] solution(String[] maps) { int[][] arr = new int[maps.length][maps[0].length()]; boolean visited[][] = new boolean[arr.length][arr[0].length]; for (int i = 0; i list = new ArrayList(); f..