StringStream & hash map||Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nSince this is an easy question, using unordered_map is good for this task.\nC++ std::st
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince this is an easy question, using unordered_map is good for this task.\nC++ `std::stringstream` is good for splitting string.\n\n2nd approach is a try by using string_view thanks the suggestions by  @sergei99 & @shahidali_sa08.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. define the function `vector<string> toStringVec(string& s)` by using stringstream to split the string `s` to a vector of strings.\n2. apply toStringVec to `s1, s2` to obtain the vectors `ss1, ss2`.\n3. Construct a hash map `freq` to count each sting\'s occurrencies in `ss1` & `ss2`.\n4. Put the string s with frequency=1 into the vector `ans`\n5. `ans` is the answer.\n6. 2nd approach is using string_view. For splitting string 2 pointers method is used.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$O(|s1|+|s2|)$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$O(|s1|+|s2|)$\n# Code||0ms Beats 100.00%\n```cpp []\nclass Solution {\npublic:\n    inline static vector<string> toStringVec(string& s){\n        stringstream ss(s);\n        vector<string> ans;\n        while (!ss.eof()){\n            string tmp;\n            ss>>tmp;\n            ans.push_back(tmp);\n        }\n        ss.clear();\n        return ans;\n    }\n    static vector<string> uncommonFromSentences(string& s1, string& s2) {\n        auto ss1=toStringVec(s1);\n        auto ss2=toStringVec(s2);\n        unordered_map<string, int> freq;\n        freq.reserve(ss1.size()+ss2.size());\n        for(auto& s: ss1) freq[s]++;\n        for(auto& s: ss2) freq[s]++;\n        vector<string> ans;\n        for(auto& [s,f]: freq){\n            if(f==1) ans.push_back(s);\n        }\n        return ans;\n    }\n};\n\n\n\nauto init = []() {\n    ios::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n    return \'c\';\n}();\n```\nstringstream is an old C++ class which is also used to solve the question  [Leetcode 592. Fraction Addition and Subtraction](https://leetcode.com/problems/fraction-addition-and-subtraction/solutions/5677011/convert-to-fractions-then-do-school-math-beats-100/)\n[Please turn on the English subtitles if necessary]\n[https://youtu.be/Al-FZ4wPmyY?si=X9GSBxTmb9DWTvGL](https://youtu.be/Al-FZ4wPmyY?si=X9GSBxTmb9DWTvGL)\n\n# C++ using string_view + 2 pointers\n```\nclass Solution {\npublic:\n    unordered_map<string_view, int> freq;\n    inline void toFreq(string& s){\n        string_view sv(s);\n        const int n=sv.size();\n        for (int l=0, r=0; r<= n; r++) {\n            if (r==n || sv[r]==\' \') {  // Word boundary\n                if (r>l) {\n                    string_view word = sv.substr(l, r-l);\n                    freq[word]++;\n                }\n                l=r+1;  // Move to the next word\n            }\n        }  \n    }\n    vector<string> uncommonFromSentences(string& s1, string& s2) {\n        freq.reserve(200);\n        toFreq(s1);\n        toFreq(s2);\n        vector<string> ans;\n        for(auto& [s, f]: freq){\n            if(f==1) ans.emplace_back(s);\n        }\n        return ans;\n    }\n};\n\n```
['Hash Table', 'Two Pointers', 'String', 'Counting', 'C++']