class Solution {
    public int solution(int n) {$
        return n % 7 == 0 ? n / 7 : n / 7 + 1;
    }
}

'공부 > 프로그래머스' 카테고리의 다른 글

피자 나눠 먹기(3)  (1) 2024.01.26
피자 나눠 먹기(2)  (0) 2024.01.26
짝수는 싫어요  (0) 2024.01.25
최빈값 구하기  (0) 2024.01.25
배열 두 배 만들기  (0) 2024.01.24

 

class Solution {
    public int[] solution(int n) {
        int length = n % 2 == 0 ? n/2 : n/2 + 1;
        int[] answer = new int[length];
        int index = 0;
        for(int i=0; i<=n; i++){
            if(i % 2 != 0){
                answer[index] = i;
                index++;
            }
        }
        return answer;
    }
}

'공부 > 프로그래머스' 카테고리의 다른 글

피자 나눠 먹기(2)  (0) 2024.01.26
피자 나눠 먹기 (1)  (0) 2024.01.26
최빈값 구하기  (0) 2024.01.25
배열 두 배 만들기  (0) 2024.01.24
분수의 덧셈  (0) 2024.01.24

 

import java.util.*;
class Solution {
    public int solution(int[] array) {
        int count = 0;
        int answer = 0;
        int maxBindo = 0;
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for(int num : array){
            int bindo = map.getOrDefault(num, 0) + 1;
            if(bindo > maxBindo){
                maxBindo = bindo;
                answer = num;
            }
            else if(bindo == maxBindo){
                answer = -1;
            }
            map.put(num, bindo);
        }
        return answer;
    }
}

'공부 > 프로그래머스' 카테고리의 다른 글

피자 나눠 먹기 (1)  (0) 2024.01.26
짝수는 싫어요  (0) 2024.01.25
배열 두 배 만들기  (0) 2024.01.24
분수의 덧셈  (0) 2024.01.24
flag에 따라 다른 값 반환하기  (0) 2024.01.23

 

class Solution {
    public int[] solution(int[] numbers) {
        int[] answer = new int[numbers.length];
        for(int i=0; i<numbers.length; i++){
            answer[i] = numbers[i] * 2;
        }
        return answer;
    }
}

'공부 > 프로그래머스' 카테고리의 다른 글

짝수는 싫어요  (0) 2024.01.25
최빈값 구하기  (0) 2024.01.25
분수의 덧셈  (0) 2024.01.24
flag에 따라 다른 값 반환하기  (0) 2024.01.23
조건 문자열  (0) 2024.01.23

+ Recent posts