https://school.programmers.co.kr/learn/courses/30/lessons/77484
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
- Java
있는 것을 넣어두고 찾는 것 HashSet이 좋으려나? 싶어서 사용했다.
import java.util.*;
class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
int[] answer = new int[2];
HashSet<Integer> aa = new HashSet<>();
int cntZ = 0;
for(int i=0;i<6;i++){
if(lottos[i]==0)
cntZ++;
aa.add(lottos[i]);
}
int m=0;
for(int i=0;i<6;i++){
if(aa.contains(win_nums[i]))
m++;
}
answer[0]=7-(cntZ+m);
if(answer[0]==7)
answer[0]=6;
answer[1]=7-m;
if(m<2)
answer[1]=6;
return answer;
}
}
- Ruby
a.include?(n) -> a에 n이 있니? true / false return
def solution(lottos, win_nums)
answer = [0,0]
cntZ=0
m=0
lottos.each{|l|
if l==0
cntZ=cntZ+1
else
if win_nums.include?(l)
m=m+1
end
end
}
answer[0]=7-cntZ-m
answer[1]=7-m
if answer[0]==7
answer[0]=6
end
if answer[1]==7
answer[1]=6
end
return answer
end
'Programmers > Java, Ruby' 카테고리의 다른 글
프로그래머스 Java / Ruby : 체육복 (0) | 2022.12.07 |
---|---|
프로그래머스 Java / Ruby : 푸드 파이트 (0) | 2022.12.05 |
프로그래머스 Java / Ruby : 콜라 문제 (0) | 2022.12.01 |
프로그래머스 Java : 다트 게임 (0) | 2022.11.29 |
프로그래머스 Java : 실패율 (0) | 2022.11.27 |