C++ best Solution || 100% beats || With explanation || Just Do It ✅
Intuition\n Describe your first thoughts on how to solve this problem. \nWe have to find the uncommon words in two sentences.\n\nCondition for uncommon:-\nA wor
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe have to find the uncommon words in two sentences.\n\nCondition for uncommon:-\nA word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst thing i did in this code is to store the words in vector string named *for_s1*, same for the other sentence and for other sentence vector string named is *for_s2*.\n\nAnd then i create a new vector string named *fina* and add both *for_s1* and *for_s2* to find the unique element.\n\nThen i simply apply two for loop and find the uncommon(unique) words in the *fina*(vector string).\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n^2)$$ \n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<string> uncommonFromSentences(string s1, string s2) {\n        \n        int n=s1.size();\n        int m=s2.size();\n\n        string ans;\n        vector<string> for_s1;\n        for(int i=0;i<n;i++)\n        {\n            ans+=s1[i];\n            if(s1[i]==\' \')\n            {\n                ans.pop_back();\n                for_s1.push_back(ans);\n                ans="";\n            }\n            \n        }\n        for_s1.push_back(ans);\n        ans="";\n\n///////\n\n        vector<string> for_s2;\n        string lol;\n        for(int i=0;i<m;i++)\n        {\n            lol+=s2[i];\n            if(s2[i]==\' \')\n            {\n                lol.pop_back();\n                for_s2.push_back(lol);\n                lol="";\n            }\n        }\n        for_s2.push_back(lol);\n        lol="";\n\n///////\n\n   vector<string> fina=for_s1;\n\n   for(int i=0;i<for_s2.size();i++)\n   {\n        fina.push_back(for_s2[i]);\n   }\n\n    vector<string> yoo;\n    for(int i=0;i<fina.size();i++)\n    {\n        int j;\n        for(j=0;j<fina.size();j++)\n        {\n            if(i!=j)\n            {\n                if(fina[i]==fina[j])\n                {\n                    break;\n                }\n            }   \n        }\n        if(j==fina.size() )\n        yoo.push_back(fina[i]);\n    }\n\n\n\n        return yoo;\n        \n    }\n};\n\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/ed0e940a-b670-4236-a92c-41f54580ac23_1726599687.2711406.jpeg)\n
['String', 'C++']