algorithm/문제 풀이
99클럽 코테 스터디 4일차 TIL - 프로그래머스 문제 : 할인 행사
ssoheeh
2024. 4. 4. 22:01

import java.io.*;
import java.util.*;
class Solution {
public int solution(String[] want, int[] number, String[] discount) {
int answer = 0;
Vector<String> v = new Vector<>();
HashMap<String, Integer> map = new HashMap<>();
HashMap<Integer, Integer> sm = new HashMap<>();
for(int i=0;i<want.length;i++){
map.put(want[i],number[i]);
v.add(want[i]);
sm.put(i,0);
}
int disLen = discount.length;
for(int i=0;i<=disLen-10;i++){
for(int j=i;j<i+10;j++){
if(map.containsKey(discount[j])){
int val = sm.get(v.indexOf(discount[j]));
sm.put(v.indexOf(discount[j]), val+1);
}else
break;;
}
int sum = 0;
for(int k=0;k<sm.size();k++){
if(sm.get(k)==number[k])
sum++;
sm.put(k,0);
}
if(sum==want.length) answer++;
//System.out.println(sm.get(1));
}
return answer;
}
}
주어지는 숫자가 늘어날수록 자료구조에서 get이든 조회든 늘일수록 안좋다
처음 방식과 푸는 방식은 비슷한데 조회 횟수를 줄이니까 통과..
프로그래머스에서 푸는 거는 결국 계속 로그 찍어보면서 풀기
오늘의 회고
- 너무 조급해하지 말자
- 내일(4/5) 학습 예정 : 스프링부트 온라인 강의 듣기