🐰 C++ || Easy Explanation || beat-100% solution
\uD83D\uDC68\u200D\uD83D\uDCBB Friend\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that motivates me to create a better post li
\uD83D\uDC68\u200D\uD83D\uDCBB Friend\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that motivates me to create a better post like this \u270D\uFE0F\n![image](https://assets.leetcode.com/users/images/2e9bb660-8a4b-467c-9abe-fa960504c1c1_1643331756.5386825.png)\n\n____________________________________________________________________________________________________________\n____________________________________________________________________________________________________________\n\n#### \u2714\uFE0F **Question Conclusion**\nDesign a data structure that supports adding new words and finding if a string matches any previously added string.\nImplement the WordDictionary class:\n1. WordDictionary() Initializes the object.\n2. void addWord(word) Adds word to the data structure, it can be matched later.\n3. bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots \'.\' where dots can be matched with any letter.\n\n#### \u2714\uFE0F **Solution - I (Optimal Approach)**\n##### **Intuition :-**\n* Here we are using unordered_map to store index as the size of word and vector of string to store words of same sizes.\n* To insert a word we just need to push the word at  `words[word.size()].push_back(word)`.\n* For search operation we just need to search at `words[word.size()]`.\n* As we have a wild operator. which can be equal to any alphabet thus we need to create a function `bool isEqual(string word1, string word2)` so that it can ignore the particular character while comparing with other characters Eg:- "a . c" == "a b c\' or vice versa "a b c" == "a . c".\n##### **Code :-**\n```\nclass WordDictionary\n{\n     unordered_map<int, vector<string>> words;\n\n     bool isEqual(string word1, string word2)\n     {\n          for (int i = 0; i < word1.size(); i++)\n          {\n               if (word2[i] == \'.\')\n                    continue;\n               if (word1[i] != word2[i])\n                    return false;\n          }\n          return true;\n     }\n\npublic:\n     WordDictionary() {}\n\n     void addWord(string word)\n     {\n          words[word.size()].push_back(word);\n     }\n\n     bool search(string word)\n     {\n          for (auto &&s : words[word.size()])\n               if (isEqual(s, word))\n                    return true;\n          return false;\n     }\n};\n```\n**Time Complexity** : `O(N * word.size())`, all words can be of the same size thus will need a traversal of vector once. \n**Space Complexity** : `O(N)`, N number of words are stored.\n_____________________________________________________________________________________________________________\n_____________________________________________________________________________________________________________\n\n\uD83D\uDCBBIf there are any suggestions/questions in my post, comment your approach below \uD83D\uDC47
['C', 'C++']