LintCode 684. Missing String

原题

LintCode 684. Missing String

Description

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"]

代码

class Solution {
public:
    /*
    * @param : a given string
    * @param : another given string
    * @return: An array of missing string
    */
    vector missingString(string str1, string str2) {
        // Write your code here
        vector vec1, vec2, res;
        split(str1, back_inserter(vec1));
        split(str2, back_inserter(vec2));
        auto it = vec1.begin();
        while (it != vec1.end()) {
            if (find(vec2.begin(), vec2.end(), *it) == vec2.end()) {
                res.push_back(*it);
            }
            it++;
        }
        return res;
    }
private:
    template
    void split(const std::string &s, Out result) {
        istringstream iss(s);
        copy(istream_iterator(iss), istream_iterator(), result);
    }
};

你可能感兴趣的:(LintCode 684. Missing String)