목차
1. 핸드폰 번호 가리기
2. 없는 숫자 더하기
3. 제일 작은 수 제거하기
class Solution {
public String solution(String phone_number) {
String answer = "";
char[] chararray = phone_number.toCharArray();
String backnumber = "";
for(int i = chararray.length - 4; i <= chararray.length - 1; i++){
backnumber += chararray[i];
}
for(int i = 0; i < chararray.length -4; i++){
answer += '*';
}
answer = answer + backnumber;
return answer;
}
}
class Solution {
public int solution(int[] numbers) {
int answer = 0;
int[] numarray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for(int i=0; i < numarray.length; i++){
for(int j=0; j < numbers.length; j++){
if(numarray[i] == numbers[j]){
numarray[i] = 0;
}
}
}
for(int i = 0; i < numarray.length; i++){
answer += numarray[i];
}
return answer;
}
}
import java.util.List;
import java.util.ArrayList;
class Solution {
public int[] solution(int[] arr) {
int min = arr[0];
List <Integer> list = new ArrayList<>();
for(int i = 1; i < arr.length; i++){
if (arr[i] < min){
min = arr[i];
}
}
for(int n : arr){
if(n != min){
list.add(n);
}
}
int[] answer = new int[list.size()];
for(int i = 0; i < list.size(); i++){
answer[i] = list.get(i);
}
return (answer.length==0) ? new int[] {-1} : answer ;
}
}