Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
Tags
- WAS란
- 파이썬 가상환경
- 프로그래머스
- WAS WebServer 차이
- 즐겨찾기가 가장 많은 식당 정보 출력하기
- Web Service Architecture
- JavaScript Obejct Notation
- spring
- 단순 반복 자동화
- BigDecimal
- 프로그래머스 SQL
- Python
- 프로그래머스 소수
- pybithumb
- 빗썸 API 사용
- java
- 변동성 돌파전략
- 와스 웹서버의 차이
- 리눅스 rwx
- 트레이딩 봇 만들기
- beautifulsoup
- 리눅스 777
- 오라클
- string format
- Web Server란
- 파이썬
- JSON특징
- 리눅스
- 파이썬 주식
- JSON 형식
Archives
- Today
- Total
IT 개발자_S
[프로그래머스] 위장 본문
반응형
● 해쉬를 사용하요 알고리즘을 만들 수 있다.
https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장
programmers.co.kr

접근방법
1. 해쉬맵을 사용하여 중복을 제거하고
2. 해당 의상의종류별로 cnt 를하여
3. 경우의수를 조합 의상종류별 *, 각 의상종류별의 합
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 0;
answer = process(clothes);
return answer;
}
public int process(String[][] clothes){
int result = 0;
int mapCnt = 0;
int forCnt = 1;
int loopCnt = 0;
HashMap<String, Integer> map = new HashMap<>();
for(int i = 0; i <=clothes[0].length; i++){
System.out.println("@" + " " + clothes[i][1]) ;
if(map.get(clothes[i][1])!= null){
map.put(clothes[i][1] , map.get(clothes[i][1]) +1);
}else{
map.put(clothes[i][1] , 1);
}
}
for(String key : map.keySet()){
System.out.println("$" + " " + key + " " + map.get(key)) ;
forCnt = forCnt* map.get(key);
mapCnt = mapCnt+ map.get(key);
loopCnt++;
}
System.out.print(mapCnt + " " + forCnt) ;
if (loopCnt == 1){
mapCnt = 0;
}
result = mapCnt + forCnt;
return result;
}
}
반응형
Comments