no image
자바 [Programmers] 1단계 - 제일 작은 수 제거하기
class Solution { public int[] solution(int[] arr) { int[] answer = new int[arr.length-1]; int min = arr[0]; int index = 0; if(arr.length == 1){ return new int[] {-1}; } for(int i : arr){ min = Math.min(min, i); } for(int i = 0; i < arr.length; i++){ if(min == arr[i]) continue; else answer[index++] = arr[i]; } return answer; } } 1. 먼저 값이 10이 들어있으면 -1을 return 해줘야하기 때문에 문자열 길이가 1이면 배열 -1을 return한다...
2024.03.08
no image
자바 [Programmers] 1단계 - 핸드폰 번호 가리기
class Solution { public String solution(String phone_number) { String answer=""; for(int i=0; i
2024.03.08
no image
자바 [Programmers] 1단계 - 나누어 떨어지는 숫자 배열, Arrays.toString()
package Programmers; import java.util.ArrayList; import java.util.Arrays; public class No1 { static int[] solution(int[] arr, int divisor) { ArrayList list = new ArrayList(); for(int i=0; i< arr.length; i++){ if(arr[i] % divisor == 0){ list.add(arr[i]); } } if(list.isEmpty()){ return new int[] {-1}; }else{ int[] answer = new int[list.size()]; for(int i=0; i 배열로 담으면 0으로 초기화되기 때문에 중간에 0이 들어가기 때문 2..
2024.03.03
no image
자바 [Programmers] 1단계 - 없는 숫자 더하기
class Solution { public int solution(int[] numbers) { int answer = 0; int[] arr = new int[10]; for(int i=0; i
2024.02.24
no image
자바 [Programmers] 1단계 - 서울에서 김서방 찾기
class Solution { public String solution(String[] seoul) { String answer = ""; for(int i=0; i
2024.02.19
no image
자바 [Programmers] 1단계 - 콜라츠 추측
class Solution { public int solution(int num) { long n = (long)num; int answer = 0; while(n!=1){ if(answer == 500){ return -1; } n = (n%2==0) ? n/2 : n*3+1; answer++; } return answer; } } 1. 매개변수 num을 int -> long형으로 변환 2. 로직 수행
2024.02.18
no image
자바 [Programmers] 1단계 - 음양 더하기
class Solution { public int solution(int[] absolutes, boolean[] signs) { int answer = 0; for(int i=0; i< signs.length; i++){ if(signs[i] == true){ answer += absolutes[i]; } else{ answer -= absolutes[i]; } } return answer; } } 매우 쉬운 문제! sigins[] 배열 안의 값이 true면 +, false면 -를 해주면 된다.
2024.02.18
no image
자바 [Programmers] 1단계 - 두 정수 사이의 합
class Solution { public long solution(int a, int b) { long answer = 0; if(a
2024.02.18