개발/코딩

[프로그래밍] 프로그래머스 예제문제 풀어보기 <체육복> 1차 실패

mabb 2022. 5. 29. 20:58
반응형
출처: 프로그래머스

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution {
    public int solution(int n, int[] lost, int[] reserve) {
       
        
        for(int i = 0 ; i < lost.length ; i ++){
            for(int j = 0 ; j < reserve.length ; j ++){
                if((reserve[j]==lost[i])|(reserve[j]==lost[i]-1)|(reserve[j]==lost[i]+1)){
                    reserve[j] = 100;
                    lost[j] = 100;
                    break;
                }
                
            }           
        }
        
        int loster = lost.length;
        for(int losterCheck : lost){
            if(losterCheck == 100){
                loster--;
            }
        }
        
      
        int answer = 0;
        answer = n-loster;
        return answer;
    }
}
cs
반응형