Published:
Updated:


Solution

class Solution {
    static int returnSum(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }

    public static int solution(int[] numbers) {
        int answer = returnSum(9);
        for (int number : numbers) {
            answer -= number;
        }
        return answer;
    }

    public static void main(String[] args) {
        System.out.println(solution(new int[]{1, 2, 3, 4, 6, 7, 8, 0}));
        System.out.print(solution(new int[]{5, 8, 4, 0, 6, 7, 9}));
    }
}

Leave a comment