반응형
7의 개수
class Solution {
public int solution(int[] array) {
int cnt = 0;
for(int n : array){
String s = n+"";
cnt += s.length() - s.replace("7","").length();
}
return cnt;
}
}
잘라서 배열로 저장하기
import java.util.*;
class Solution {
public List<String> solution(String my_str, int n) {
ArrayList<String> answer = new ArrayList<String>();
int i = 0;
while(true){
if(i + n>=my_str.length()){
answer.add(my_str.substring(i,my_str.length()));
break;
}
answer.add(my_str.substring(i,i+n));
i+= n;
}
return answer;
}
}
중복된 숫자 개수
class Solution {
public int solution(int[] array, int n) {
int cnt = 0;
for(int an : array){
if(an == n){
cnt++;
}
}
return cnt;
}
}
머쓱이보다 키 큰 사람
class Solution {
public int solution(int[] array, int height) {
int answer = 0;
for(int n : array){
if(n > height){
answer++;
}
}
return answer;
}
}
728x90
반응형
'CodingTest' 카테고리의 다른 글
코딩테스트 입문 - Day 21 (0) | 2025.05.05 |
---|---|
코딩테스트 입문 - Day 20 (1) | 2025.05.05 |
코딩테스트 입문 - Day 18 (1) | 2025.04.27 |
코딩테스트 입문 - Day 17 (0) | 2025.04.27 |
코딩테스트 입문 - Day 16 (0) | 2025.04.27 |