Missing String
描述:
Given two strings, you have to find the missing string.
Example
Given a string str1 = This is an example
Given another string str2 = is example
Return ["This", "an"]
代码
1 class Solution { 2 public: 3 /* 4 * @param : a given string 5 * @param : another given string 6 * @return: An array of missing string 7 */ 8 vector<string> missingString(string str1, string str2) { 9 // Write your code here 10 vector<string> vec1; 11 vector<string> vec2; 12 vector<string> res; 13 14 string buf; 15 stringstream ss1(str1); //字符流 16 while (ss1 >> buf) { 17 vec1.push_back(buf); 18 } 19 20 stringstream ss2(str2); 21 while (ss2 >> buf) { 22 vec2.push_back(buf); 23 } 24 25 26 for (int i = 0; i < vec1.size(); i++) { 27 vector<string>::iterator it; 28 it = find(vec2.begin(), vec2.end(), vec1[i]); 29 if (it == vec2.end()) { 30 res.push_back(vec1[i]); 31 } 32 } 33 return res; 34 } 35 };