반응형
배열 자르기
class Solution {
public int[] solution(int[] numbers, int num1, int num2) {
int[] answer = new int[num2 - num1 + 1];
for(int i = 0; i< answer.length; i++){
answer[i] = numbers[i+num1];
}
return answer;
}
}
외계 행성의 나이
class Solution {
public String solution(int age) {
String sAge = String.valueOf(age);
StringBuilder sb = new StringBuilder();
for(int i = 0; i< sAge.length();i ++){
sb.append((char)(sAge.charAt(i)+49));
}
return sb.toString();
}
}
진료 순서 정하기
import java.util.Arrays;
class Solution {
public int[] solution(int[] emergency) {
int[] arr = emergency.clone();
Arrays.sort(emergency);
int []answer = new int[emergency.length];
for(int i = 0; i < emergency.length;i++) {
int rank = emergency[emergency.length - i - 1];
for(int j = 0; j< emergency.length;j++) {
if(rank == arr[j]) {
answer[j] = i+1;
break;
}
}
}
return answer;
}
}
순서쌍의 개수
class Solution {
public int solution(int n) {
int cnt = 0;
for(int i = 1; i <= n/2; i++){
if(n%i==0){
cnt++;
}
}
return cnt + 1;
}
}
728x90
반응형
'CodingTest' 카테고리의 다른 글
코딩테스트 입문 - Day 9 (0) | 2025.04.20 |
---|---|
프로그래머스 - 특수문자 출력하기 (1) | 2025.04.12 |
코딩테스트 입문 - Day 7 (0) | 2025.04.12 |
코딩테스트 입문 - Day 6 (0) | 2025.04.12 |
코딩테스트 입문 - Day 5 (0) | 2025.04.12 |