본문 바로가기

Coding Test

(221)
[프로그래머스/자바] 순서쌍의 개수 class Solution { public int solution(int n) { int answer = 0; for(int i=1; i
[프로그래머스/자바] 정수 찾기 class Solution { public int solution(int[] num_list, int n) { for(int i : num_list) { if(i == n) return 1; } return 0; } }
[프로그래머스/자바] flag에 따라 다른 값 반환하기 class Solution { public int solution(int a, int b, boolean flag) { return flag == true ? (a + b) : (a - b); } }
[프로그래머스/자바] n의 배수 class Solution { public int solution(int num, int n) { return num % n == 0 ? 1 : 0; } }
[프로그래머스/자바] 모의고사 import java.util.ArrayList; import java.util.List; class Solution { public int[] solution(int[] answers) { int[] student1 = {1, 2, 3, 4, 5}; int[] student2 = {2, 1, 2, 3, 2, 4, 2, 5}; int[] student3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; int[] score = {0, 0, 0}; for(int i=0; i
[프로그래머스/자바] 체육복 import java.util.HashSet; class Solution { public int solution(int n, int[] lost, int[] reserve) { HashSet reserveSet = new HashSet(); HashSet lostSet = new HashSet(); for(int l : lost) { lostSet.add(l); } for(int r : reserve) { if(lostSet.contains(r)) { lostSet.remove(r); } else { reserveSet.add(r); } } for (int i : reserveSet) { if (lostSet.contains(i - 1)) { lostSet.remove(i - 1); } else if (..
[프로그래머스/자바] 편지 class Solution { public int solution(String message) { return message.length() * 2; } }
[프로그래머스/자바] 배열 두 배 만들기 class Solution { public int[] solution(int[] numbers) { for(int i=0; i i * 2).toArray(); } }