[Programmers] 전화번호 목록

Time Lapse :3min 0sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

bool solution(vector<string> phone_book) {
sort(phone_book.begin(),phone_book.end());
for(int i=0;i<phone_book.size()-1;i++){
if(phone_book[i].length()>phone_book[i+1].length())
continue;
for(int j=0;j<phone_book[i].length();j++){
if(phone_book[i][j]!=phone_book[i+1][j])
break;
if(j==phone_book[i].length()-1)
return false;
}
}
return true;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/phoneBookList/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.