Algorithm/Hash
-
프로그래머스 고득점 kit(유형정리) - 베스트앨범Algorithm/Hash 2023. 1. 25. 14:27
코딩테스트 연습 - 베스트앨범 | 프로그래머스 스쿨 (programmers.co.kr) 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 설명 스트리밍 사이트에서 장르 별로 가장 많이 재생된 노래를 두 개씩 모아 베스트 앨범을 출시하려 합니다. 노래는 고유 번호로 구분하며, 노래를 수록하는 기준은 다음과 같습니다. 속한 노래가 많이 재생된 장르를 먼저 수록합니다. 장르 내에서 많이 재생된 노래를 먼저 수록합니다. 장르 내에서 재생 횟수가 같은 노래 중에서는 고유 번호가 낮은 노래를 먼저 수록합니다. 노래의 장르를 나타내는 문자열 배열 genres와 노래..
-
프로그래머스 고득점 kit(유형정리) - 위장Algorithm/Hash 2023. 1. 24. 17:34
코딩테스트 연습 - 위장 | 프로그래머스 스쿨 (programmers.co.kr) 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 설명 스파이들은 매일 다른 옷을 조합하여 입어 자신을 위장합니다. 예를 들어 스파이가 가진 옷이 아래와 같고 오늘 스파이가 동그란 안경, 긴 코트, 파란색 티셔츠를 입었다면 다음날은 청바지를 추가로 입거나 동그란 안경 대신 검정 선글라스를 착용하거나 해야 합니다. 종류이름 얼굴 동그란 안경, 검정 선글라스 상의 파란색 티셔츠 하의 청바지 겉옷 긴 코트 스파이가 가진 의상들이 담긴 2차원 배열 clothes가 주어질 때 서로..
-
프로그래머스 고득점 kit(유형정리) - 전화번호 목록Algorithm/Hash 2023. 1. 24. 16:43
코딩테스트 연습 - 전화번호 목록 | 프로그래머스 스쿨 (programmers.co.kr) 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 설명 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. 구조대 : 119 박준영 : 97 674 223 지영석 : 11 9552 4421 전화번호부에 적힌 전화번호를 담은 배열 phone_book 이 solution 함수의 매개변수로 주어질 때, 어떤 번호가 다른 번호의 접두어인 경우가 ..
-
프로그래머스 고득점 kit(유형정리) - 완주하지 못한 선수Algorithm/Hash 2023. 1. 23. 11:31
코딩테스트 연습 - 완주하지 못한 선수 | 프로그래머스 스쿨 (programmers.co.kr) 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 설명 수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수들의 이름이 담긴 배열 completion이 주어질 때, 완주하지 못한 선수의 이름을 return 하도록 solution 함수를 작성해주세요. 제한사항 마라톤 경기에 참여한 선수의 수는 1명 이상 100,000명 ..
-
프로그래머스 고득점 kit(유형정리) - 폰켓몬Algorithm/Hash 2023. 1. 23. 10:51
코딩테스트 연습 - 폰켓몬 | 프로그래머스 스쿨 (programmers.co.kr) 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 설명 당신은 폰켓몬을 잡기 위한 오랜 여행 끝에, 홍 박사님의 연구실에 도착했습니다. 홍 박사님은 당신에게 자신의 연구실에 있는 총 N 마리의 폰켓몬 중에서 N/2마리를 가져가도 좋다고 했습니다. 홍 박사님 연구실의 폰켓몬은 종류에 따라 번호를 붙여 구분합니다. 따라서 같은 종류의 폰켓몬은 같은 번호를 가지고 있습니다. 예를 들어 연구실에 총 4마리의 폰켓몬이 있고, 각 폰켓몬의 종류 번호가 [3번, 1번, 2번, 3번]..
-
HashMap 예제 #2Algorithm/Hash 2022. 1. 10. 11:01
프로그래머스 해시 파트 level 2 첫 번째 문제에 이어 두 번째 문제 위장문제를 도전해 보았다. 문제는 이러하다. 뭔가 문제에서 부터 Map을 쓰면 편할 것 같은 느낌이 확 풍겨온다. 하지만 막상 문제를 읽으면 서로 다른 옷의 조합의 수를 return 하란다 ㅋㅋㅋ 여튼 그럼 그냥 종류를 key로, 개수를 value로 하면 대놓고 Map으로 풀 수 있을것 같다. 제한 사항들과 함께 알고리즘을 생각해 보자. 1. clothes 배열을 보면 의상의 종류가 인덱스 [1] 부터 나열되고 있으므로, clothes[i][1] 인덱스를 사용해서 풀 수 있을 것 같다. 2. 같은 이름의 의상이 존재하지 않으므로, set이나 Map을 쓰면 될 듯하다. 3. clothes 원소가 문자열이므로, 제네릭안에 key의 타입..
-
Map 개념 및 예제Algorithm/Hash 2022. 1. 5. 16:53
지난 시간 Set에 이어 이번 시간에는 Map에 대해서 다루어 보았다. Map : 자료를 쌍으로 관리하는데 최적화 된 인터페이스이다. -> key-value쌍으로 이루어져 있고, key값은 유일하고, value 값은 중복될 수 있다. Map map = new HashMap(); 와 같은 형식으로 사용한다. -> put() : set에서 add() 메소드와 유사하며 key, value쌍을 모두 추가해야 하므로 put(~~, ~~) 형식으로 사용한다. remove() : 제거하는 메소드 get(key) : key와 쌍을 이루고 있는 value값 불러오기 containsKey() : 해당 key값이 객체에 존재하는지 확인 간단하게 Map에 대해서 설명을 했고, 예제를 통해 어떤식으로 사용할 수 있는지를 확인해..
-
HashSet 예제 #2Algorithm/Hash 2021. 12. 29. 10:59
HashSet을 활용한 예제 하나를 더 풀어보자. #2. 백준 1764 듣보잡 문제 듣도 못한 사람과 보도 못한 사람의 숫자를 입력받고 그만큼씩 사람 이름을 입력받는다. 그리고 듣도 보도 못한 사람을 출력하면 된다. 듣도 못한 사람 집합과 보도 못한 사람 집합의 교집합에 있는 사람 이름을 뽑아 내면 되겠다. 어? 그럼 교집합이면 중복이네? 이 점에 착안해서 set의 contains() 메소드를 활용하여 set에 포함되어 있으면 출력시키는 프로그램을 짜보면 될 듯하다. 시간을 조금 더 단축시키기 위해 BufferedReader와 BufferedWriter를 사용했고, 출력도 bw.write를 사용하여 출력했다. HashSet에 듣도 못한 사람을 입력시키고, str에 보도 못한 사람을 입력시킨다. 그리고 듣..