[프로그래머스] 체육복-탐욕법(Greedy) Level1 (자바,java)

[프로그래머스] 체육복-탐욕법(Greedy) Level1 (자바,java)

- 풀이

[n+1]의 arr 배열을 만든다.

arr을 1로 채워주고 0번 index만 0으로한다.

n+1로 잡았기때문에 i를 2부터 탐색하여 체육복을 나눠준다.

최종적으로 0이 아닌수를 카운트해준다.

입출력 예제1

import java.util.Arrays; class Solution { public int solution(int n, int[] lost, int[] reserve) { int answer = 0; int[] arr= new int[n+1]; Arrays.fill(arr,1); arr[0]=0; for (int i=0; i

from http://rotomoo.tistory.com/23 by ccl(A) rewrite - 2021-11-02 13:01:28