전체 글 963

[programmers] 이상한 문자 만들기

문제https://school.programmers.co.kr/learn/courses/30/lessons/12930 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public String solution(String s) { String answer = ""; int idx = 0; for (int i = 0; i 문자열을 순회하며 공백일 때는 idx를 0으로, 공백이 아닐 때는 idx 값을 늘려가며 짝수번째 인지 홀수번째인지 확인한다. 짝수번째라면 대문자로, 홀수번째라면 소문자로 바꿔 answer에 저장한다. 출처: 프로그래머스 코딩 테스트 연습..

[programmers] 핸드폰 번호 가리기

문제https://school.programmers.co.kr/learn/courses/30/lessons/12948 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public String solution(String phone_number) { String answer = ""; for (int i = 0; i answer에 전체 문자열의 길이에서 4를 뺀 길이만큼 *로 채운다. 이후 문자열 뒷 4자리를 answer에 저장한다. 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challen..

[programmers] 콜라츠 추측

문제https://school.programmers.co.kr/learn/courses/30/lessons/12943 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(int num) { int answer = 0; long n = num; while (n != 1) { if (answer >= 500) { answer = -1; break; } if (n % 2 == 0) { n /= 2; } else { n = n * 3 + 1; } answer += 1; } return ..

[programmers] 나누어 떨어지는 숫자 배열

문제https://school.programmers.co.kr/learn/courses/30/lessons/12910 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int[] solution(int[] arr, int divisor) { int[] answer = {}; ArrayList list = new ArrayList(); for (int num : arr) { if (num % divisor == 0) { list.add(num); } } if (list.size() == 0) { ..

[programmers] 전국 대회 선발 고사

문제https://school.programmers.co.kr/learn/courses/30/lessons/181851 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int solution(int[] rank, boolean[] attendance) { int answer = 0; ArrayList list = new ArrayList(); for (int i = 0; i () { @Override public int compare(int[] o1, int[] o2) { return o1[1] -..

[programmers] 소인수분해

문제https://school.programmers.co.kr/learn/courses/30/lessons/120852 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int[] solution(int n) { int[] answer = {}; HashSet set = new HashSet(); while (n > 1) { for (int i = 2; i 2부터 n이하까지 순회하며 n이 나눠지는지 확인한다. 나눠진다면 set에 나눈 값을 저장하고 n을 업데이트한다. 이 과정을 n이 1보다 클 때 계속해서..

[programmers] 한 번만 등장한 문자

문제https://school.programmers.co.kr/learn/courses/30/lessons/120896 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public String solution(String s) { String answer = ""; HashMap map = new HashMap(); for (int i = 0; i list = new ArrayList(map.keySet()); Collections.sort(list, new Comparator() { @Override publi..

[programmers] 숨어있는 숫자의 덧셈 (2)

문제https://school.programmers.co.kr/learn/courses/30/lessons/120864 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(String my_string) { int answer = 0; String str = ""; for (int i = 0; i 0) { answer += Integer.parseInt(str); str = ""; } } } if (str.length() > 0) { answer += Integer.parseInt(str);..

[programmers] 모스부호 (1)

문제https://school.programmers.co.kr/learn/courses/30/lessons/120838 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public String solution(String letter) { String answer = ""; HashMap map = new HashMap(); map.put(".-", 'a'); map.put("-...", 'b'); map.put("-.-.", 'c'); map.put("-..", 'd'); map.put(".", 'e'); map..

[programmers] 진료순서 정하기

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