반응형
숫자 찾기
class Solution {
public int solution(int num, int k) {
String s = String.valueOf(num);
String k1 = String.valueOf(k);
int n = s.indexOf(k1);
if(n == -1){
return -1;
}
return n+1;
}
}
n의 배수 고르기
import java.util.*;
class Solution {
public List<Integer> solution(int n, int[] numlist) {
List<Integer> arr = new ArrayList<>();
for(int num : numlist){
if(num%n == 0){
arr.add(num);
}
}
return arr;
}
}
자릿수 더하기
class Solution {
public int solution(int n) {
int sum = 0;
int divn = 10;
while(n> 0){
sum += n%divn;
n /= 10;
}
return sum;
}
}
OX 퀴즈
import java.util.*;
class Solution {
public List<String> solution(String[] quiz) {
List<String> arr = new ArrayList<>();
for(String s : quiz){
String[] sar = s.split(" ");
int n1 = Integer.parseInt(sar[0]);
int n2 = Integer.parseInt(sar[2]);
int res = Integer.parseInt(sar[4]);
if(sar[1].equals("+") && n1 + n2 == res){
arr.add("O");
}else if(sar[1].equals("-") && n1 - n2 == res){
arr.add("O");
}
else{
arr.add("X");
}
}
return arr;
}
}
728x90
반응형
'CodingTest' 카테고리의 다른 글
코딩테스트 입문 - Day 19 (0) | 2025.05.05 |
---|---|
코딩테스트 입문 - Day 18 (1) | 2025.04.27 |
코딩테스트 입문 - Day 16 (0) | 2025.04.27 |
코딩테스트 입문 - Day 15 (0) | 2025.04.27 |
코딩테스트 입문 - Day 14 (1) | 2025.04.27 |