https://school.programmers.co.kr/learn/courses/30/lessons/132265
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
private static final int SIZE = 10_000;
public int solution(int[] topping) {
int answer = 0;
int[][] numCnt = new int[2][10_000+1];
int[] cnt = new int[2];
for(int i = 0 ; i < topping.length ; i++){
if(numCnt[1][topping[i]] == 0){
cnt[1]++;
}
numCnt[1][topping[i]]++;
}
for(int i = 0 ; i < topping.length ; i++){
if(numCnt[0][topping[i]] == 0){
cnt[0]++;
}
numCnt[0][topping[i]]++;
numCnt[1][topping[i]]--;
if(numCnt[1][topping[i]] == 0){
cnt[1]--;
}
if(cnt[0] == cnt[1]){
answer++;
}
}
return answer;
}
}
'알고리즘' 카테고리의 다른 글
백준 25418번 정수 a를 k로 만들기 (JAVA) (0) | 2022.10.23 |
---|---|
프로그래머스 숫자 짝꿍 (JAVA) (0) | 2022.10.22 |
프로그래머스 콜라 문제 (JAVA) (0) | 2022.10.20 |
프로그래머스 문자열을 정수로 바꾸기 (JAVA) (0) | 2022.10.19 |
프로그래머스 2개 이하로 다른 비트 (JAVA) (0) | 2022.10.18 |