반응형
코딩테스트 연습 - 전화번호 목록
전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. 구조
programmers.co.kr
set에 모든 전화번호를 담아주고, 각 전화번호가 다른 전화번호의 접두어인지 확인해주었습니다.
#include <string>
#include <vector>
#include <set>
using namespace std;
bool solution(vector<string> phone_book) {
set<string> st(phone_book.begin(), phone_book.end());
for(auto it = st.begin(); it != st.end(); it++)
for(int i=1; i< it->size(); i++)
if(st.find(it->substr(0, i)) != st.end()) return false;
return true;
}
반응형
'Algorithm' 카테고리의 다른 글
프로그래머스 : 더 맵게 (0) | 2021.11.14 |
---|---|
프로그래머스 : 카펫 (0) | 2021.11.14 |
프로그래머스 : 기지국 설치 (0) | 2021.11.14 |
프로그래머스 : 길 찾기 게임 (0) | 2021.11.14 |
프로그래머스 : 외벽 점검 (0) | 2021.11.14 |