Archive
2020.04.08
#include #include #include using namespace std; bool solution(vector phone_book) { bool answer = true; sort(phone_book.begin(), phone_book.end()); for(int i = 0 ; i < phone_book.size() - 1;i++) { if (phone_book[i] == phone_book[i+1].substr(0, phone_book[i].length())) answer = false; } return answer; }
Archive
2020.04.08
#include #include using namespace std; vector solution(vector heights) { vector answer; answer.resize(heights.size(), 0); // 제일 오른쪽에 있는 타워부터 탐색 for (int curr = heights.size() - 1; curr >= 0; --curr) { int currHeight = heights[curr]; for (int compare = curr - 1; compare >= 0; --compare) { if (heights[compare] > currHeight) { answer[curr] = compare + 1; break; } } } return answer; }
Archive
2020.03.12
#include #include #include #include using namespace std; vector solution(vector array, vector commands) { vector answer; int i, j, k; for(int m = 0 ; m < commands.size(); m++) { i = commands[m][0]; j = commands[m][1]; k = commands[m][2]; vector temp (j - i + 1); for(int n = i ; i
Archive
2020.03.12
#include #include #include using namespace std; string solution(vector participant, vector completion) { string answer = ""; sort(participant.begin(), participant.end()); sort(completion.begin(),completion.end()); for(int i = 0 ; i < participant.size(); i++) { if(participant[i] != completion[i]) { return participant[i]; } } return answer; }