#include <string>
#include <vector>

using namespace std;

bool solution(vector<string> phone_book) {
    bool answer = true;
    int min = phone_book[0].length();
    int min_num=0;
    for(int i=1; i < phone_book.size(); i++){
        if(phone_book[i].length() < min){
            min_num = i;
            min= phone_book[i].length();
        }
    }
    string min_s = phone_book[min_num];
    string tmp;
    
    for(int i=0; i < phone_book.size(); i++){
        if(i == min_num)
            continue;
        int cnt = 0;
        answer = true;
        
        tmp = phone_book[i];
        for(int j = 0; j < min_s.length(); j++){
            if(tmp[j] != min_s[j])
                break;
            else{
                cnt++;
            }
        }
        if(cnt == min_s.length())
        {
            answer = false;
            break;
        }
        
    }
    return answer;
}

'자윤이와고리즘 > Code' 카테고리의 다른 글

[프로그래머스] 올바른 괄호  (0) 2019.07.22
[프로그래머스] 카펫  (0) 2019.07.22
[프로그래머스] 큰 수 만들기  (0) 2019.07.22
[프로그래머스] 쇠막대기  (0) 2019.07.22
[프로그래머스] 기능개발  (0) 2019.07.22

+ Recent posts