728x90
반응형
SMALL
프로그래머스 Level 1 체육복을 자바를 통해 풀어보았다.
programmers.co.kr/learn/courses/30/lessons/42862
Level 1 - 체육복.java
#Level 1 체육복.java
import java.util.Arrays;
class Solution {
public int solution(int n, int[] lost, int[] reserve) {
int[] delete = new int[0];
for(int i=0;i<lost.length;i++){
for(int j=0;j<reserve.length;j++){
if(lost[i]==reserve[j]){
int add = delete.length;
delete = Arrays.copyOf(delete,add+1);
delete[add] = lost[i];
break;
}
}
}
for(int i=0;i<delete.length;i++){
for(int j=0;j<lost.length;j++){
if(delete[i]==lost[j]){
lost[j]=0;
}
}
for(int j=0;j<reserve.length;j++){
if(delete[i]==reserve[j]){
reserve[j]=0;
}
}
}
int lost_count = 0;
for(int i=0;i<lost.length;i++){
if(lost[i]!=0){
lost_count++;
}
}
int stu_num = n - lost_count;
for(int i=0;i<lost.length;i++){
for(int j=0;j<reserve.length;j++){
if(lost[i] != 0 && reserve[j] !=0 && lost[i]-1 == reserve[j]){
lost[i] = 0;
reserve[j] = 0;
stu_num ++;
}
else if((lost[i] != 0) && reserve[j] !=0 && (lost[i]+1 == reserve[j])){
lost[i] = 0;
reserve[j] = 0;
stu_num ++;
}
}
}
int answer = stu_num;
return answer;
}
}
728x90
반응형
SMALL
'Problem Solving > programmers' 카테고리의 다른 글
[Programmers] Level 1 K번째수.java (0) | 2021.04.27 |
---|---|
[Programmers] Level 1 체육복.py (0) | 2021.04.27 |
[Programmers] Level 1 모의고사.py (0) | 2021.04.26 |
[Programmers] Level 1 완주하지 못한 선수.java (0) | 2021.04.26 |
[Programmers] Level 1 크레인 인형뽑기 게임.py (0) | 2021.04.26 |