본문 바로가기

Coding Test

(221)
[프로그래머스/자바] 없는 숫자 더하기 class Solution { public int solution(int[] numbers) { int answer = 45; for (int number : numbers){ answer -= number; } return answer; } }
[프로그래머스/자바] 점의 위치 구하기 class Solution { public int solution(int[] dot) { if(dot[0]>0 && dot[1]>0) return 1; else if(dot[0]0) return 2; else if(dot[0]
[프로그래머스/자바] 중복된 숫자 개수 class Solution { public int solution(int[] array, int n) { int answer = 0; for(int number : array){ if(number == n) answer++; } return answer; } } import java.util.Arrays; class Solution { public int solution(int[] array, int n) { return (int) Arrays.stream(array).filter(i -> i == n).count(); } } 스트림을 이용한 풀이
[프로그래머스/자바] 배열 원소의 길이 class Solution { public int[] solution(String[] strlist) { int[] answer = new int[strlist.length]; for(int i=0; i
[프로그래머스/자바] 개미 군단 class Solution { public int solution(int hp) { int answer = 0; while(hp>=5){ hp-=5; answer++; } while(hp>=3){ hp-=3; answer++; } while(hp>0){ hp--; answer++; } return answer; } } class Solution { public int solution(int hp) { return hp / 5 + (hp % 5 / 3) + (hp % 5 % 3); } }
[프로그래머스/자바] 자릿수 더하기 class Solution{ public int solution(int n) { int answer = 0; while (n > 0) { answer += n % 10; n /= 10; } return answer; } }
[코드업/자바] 3004 - 데이터 재정렬 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; List list = new ArrayList(); for(int i=0; i
[코드업/자바] 1805 - 입체기동장치 생산공장 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); List devices = new ArrayList(); int n = sc.nextInt(); for(int i=0; i