Skip to content

Commit b9f7e75

Browse files
Added comments
Added meaningful comments in the appropriate places
1 parent 351400d commit b9f7e75

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Strings/findAndReplacePattern.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ vector<string> findAndReplacePattern(vector<string> &words, string pattern)
3434
for (int i = 0; i < words.size(); i++)
3535
{
3636
bool flag = true;
37-
unordered_map<char, char> wordToPattern;
38-
unordered_map<char, char> patternToWord;
37+
unordered_map<char, char> wordToPattern; // Map to match given word with given pattern
38+
unordered_map<char, char> patternToWord; // Map to match given pattern with given word
3939
for (int j = 0; j < pattern.length(); j++)
4040
{
4141
char wc = words[i][j];
4242
char pc = pattern[j];
43-
if (wordToPattern.count(wc) < 1)
43+
if (wordToPattern.count(wc) < 1) // checking if corresponding character of word is present in wordToPatterrn map
4444
wordToPattern[wc] = pc;
45-
if (patternToWord.count(pc) < 1)
45+
if (patternToWord.count(pc) < 1) // checking if corresponding character of pattern is present in patternToWord map
4646
patternToWord[pc] = wc;
4747

48-
if (patternToWord[pc] != wc || wordToPattern[wc] != pc)
48+
if (patternToWord[pc] != wc || wordToPattern[wc] != pc) // Checking if there is a mismatch of the corresponding characters in both the maps
4949
{
5050
flag = false;
5151
break;
@@ -57,7 +57,7 @@ vector<string> findAndReplacePattern(vector<string> &words, string pattern)
5757
return ans;
5858
}
5959

60-
int main()
60+
int main() // driver function
6161
{
6262
vector<string> words={"abc","deq","mee","aqq","dkd","ccc"};
6363
string pattern="abb";

0 commit comments

Comments
 (0)