[프로그래머스, Java] 덧칠하기
·
CodingTest/Programmers
💡풀이import java.util.Arrays;import java.util.stream.IntStream;class Solution { public int solution(int n, int m, int[] section) { boolean[] painted = new boolean[n + 1]; Arrays.fill(painted, true); // n을 1로 채운 배열로 만든다 for (int s : section) { // section 위치는 0으로 바꾼다 painted[s] = false; } int count = 0; // section으로 분기한다 for (int i = 0;..
[프로그래머스, Java] 모의고사
·
CodingTest/Programmers
💡풀이import java.util.Arrays;import java.util.stream.IntStream;class Solution { public int[] solution(int[] answers) { int[][] points = {{1, 2, 3, 4, 5}, {2, 1, 2, 3, 2, 4, 2, 5}, {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}}; int[] results = new int[3]; for (int i = 0; i results[e - 1] == max) .toArray(); }} GitHub - okjunghyeon/Programmers_CodingTest: 프로그래머스 관련 코딩테..
[프로그래머스, Java] 2016년
·
CodingTest/Programmers
💡풀이class Solution { public String solution(int a, int b) { // 2016년 1월 1일은 금요일입니다. int[] days = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; String[] months = {"THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED"}; // 1 index를 금요일로 위치함 int count = 0; // a-1 달 까지 총 일수를 구한다 for (int i = 0; i 💡풀이 2import java.time.LocalDate;class Solution { public S..
[프로그래머스, Java] 폰켓몬
·
CodingTest/Programmers
💡풀이import java.util.Arrays;import java.util.Set;import java.util.stream.Collectors;class Solution { public int solution(int[] nums) { // 중복 포켓몬 제거 Set set = Arrays.stream(nums) .boxed() .collect(Collectors.toSet()); return Math.min(set.size(), nums.length / 2); }} 📖새로 배운 부분// ❌ 컴파일 에러!int[] nums = {1, 2, 3};Set set = new HashSet(..
[프로그래머스, Java] 기사단원의 무기
·
CodingTest/Programmers
💡풀이import java.util.stream.IntStream;class Solution { public int solution(int number, int limit, int power) { // 1~number 기사단원으로 분기한다 // 기사번호의 약수의 개수를 구한다. // 약수의 개수가 limit를 초과할경우 power를, 초과하지않으면 약수의 개수를 result에 더한다 return IntStream.rangeClosed(1, number) .map(e -> { int count = 0; for(int i=1; i limit ? power :..
[프로그래머스, Java] 추억 점수
·
CodingTest/Programmers
💡풀이- HashMap 활용import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.Map;class Solution { public int[] solution(String[] name, int[] yearning, String[][] photo) { // 이름과 그리움 점수를 매핑하는 맵 생성 Map map = new HashMap(); // 이름 배열을 순회하며 맵에 이름과 그리움 점수 저장 for (int i = 0; i answer = new ArrayList(); // 각 사진에 대해 그리움 점수 계산 f..