C++ :Two  easy and simple  methods, Problem Solving Approach for Uncommon Words from Sentences
 # Intuition  \n\n\n# Approach\nUsing Two Loops \uD83D\uDD04:\n 1. Process Each String:\nThe code manually processes s1 and s2 to extract words by iterating thr
<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUsing Two Loops \uD83D\uDD04:\n 1. **Process Each String:\nThe code manually processes s1 and s2 to extract words by iterating through each character. It uses substr() to get words and updates a map to count occurrences.**\n2. **Map for Word Frequency \uD83D\uDDC2\uFE0F:\nWords are stored in an unordered_map<string, int>, where the key is the word and the value is the count of appearances across both sentences.**\n3. **Final Check \u2705: Filter Uncommon Words: After processing both strings, the map is checked for words with exactly one occurrence (elem.second == 1). These words are added to the result vector v.**\n\n 4. Reverse the Result \uD83D\uDD04:\nUnnecessary Step: The result vector v is reversed before returning. This step may not be required depending on the problem\'s requirements.\n\nKey Steps \uD83D\uDEE0\uFE0F:\n\n1. Manual Word Extraction: Extract words by iterating through characters and handling spaces.\n1. Storing Frequencies: Use a map to keep track of how many times each word appears.\n1. Filtering and Reversing: Identify uncommon words and store them in a vector. The vector is then reversed (potentially unnecessarily).\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n<!-- - Time complexity: -->\n - Time Complexity \u23F3:O(n1 + n2 + k): Linear time with respect to the combined lengths of the input strings s1 and s2, and the number of unique words k.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n<!-- - Space complexity: -->\n- Space Complexity \uD83D\uDCBE:\nO(k + u): Linear space complexity depending on the number of unique words k and uncommon words u.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\n\n![image.png](https://assets.leetcode.com/users/images/8c2fd5e2-7e12-4fbd-aa9d-8c85e2e91951_1726667524.9295502.png)\n\n```cpp []\nclass Solution {\npublic:\n    map<string,int>mp;\n   vector<string> splitStringBySpace(const string& str) {\n    vector<string> result;\n    istringstream iss(str);\n    string word;\n    while (iss >> word) {\n        result.push_back(word);}\n    return result;}\n    vector<string> uncommonFromSentences(string s1, string s2){\n        vector<string> v1= splitStringBySpace(s1);\n        vector<string> v2= splitStringBySpace(s2);\n        for(int i=0;i<v1.size();i++){\n           mp[v1[i]]++;}\n        for(int i=0;i<v2.size();i++){\n             mp[v2[i]]++;}\n        vector<string>ans;\n        for(auto &elem : mp){\n            if(elem.second==1){\n                ans.push_back(elem.first);}}\n        return ans;\n    }\n};\n```\n![Screenshot 2024-09-18 191958.png](https://assets.leetcode.com/users/images/387349ad-96e2-4cb3-bf2b-3728fe5e5e11_1726667465.4087603.png)\n```\nclass Solution {\npublic:\n    map<string,int>mp;\n   vector<string> splitStringBySpace(const string& str) {\n    vector<string> result;\n    istringstream iss(str);\n    string word;\n    while (iss >> word) {\n        result.push_back(word);}\n    return result;}\n    vector<string> uncommonFromSentences(string s1, string s2){\n        vector<string> v1= splitStringBySpace(s1);\n        vector<string> v2= splitStringBySpace(s2);\n        for(int i=0;i<v1.size();i++){\n           mp[v1[i]]++;}\n        for(int i=0;i<v2.size();i++){\n             mp[v2[i]]++;}\n        vector<string>ans;\n        for(auto &elem : mp){\n            if(elem.second==1){\n                ans.push_back(elem.first);}}\n        return ans;\n    }\n};\n```\n
['String', 'C++']