2 ["qws", "sqwes", "sqwe"] [0, 0]
2 ["qws", "sqsqwes", "sqwes"] [0, 0]
2 ["qws", "sqsqwess", "sqwes"] [0, 0]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #include <string> #include <vector> #include <iostream> using namespace std; vector<int> solution(int n, vector<string> words) { vector<int> answer; int i; string all = words[0]+" "; for (i = 1; i < words.size(); i++) { if (words[i - 1][words[i - 1].size() - 1] != words[i][0]) break; if( (all.find(words[i])!=string::npos)) break; all += words[i]+" "; } if (i == words.size()) { answer.push_back(0); answer.push_back(0); } else { answer.push_back(i%n+1); answer.push_back(i/n+1); } return answer; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <string> #include <vector> #include <iostream> using namespace std; vector<int> solution(int n, vector<string> words) { vector<int> answer; int i; string all = words[0]+" "; for (i = 1; i < words.size(); i++) { if (words[i - 1][words[i - 1].size() - 1] != words[i][0]) break; if( (all.find(words[i])!=string::npos)) break; all += words[i]+" "; } if (i == words.size()) { answer.push_back(0); answer.push_back(0); } else { answer.push_back(i%n+1); answer.push_back(i/n+1); } return answer; }
감사합니다 20번 해결 계속 안되서 뭐가 문제지 하다가 이거 봐서 해결했습니다 ㅎㅎ