valid-anagram 1.0.0
Valid Anagram
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

bool isAnagram (string s, string t)
 

Detailed Description

Definition at line 25 of file main.cpp.

Member Function Documentation

◆ isAnagram()

bool Solution::isAnagram ( string  s,
string  t 
)
inline

Definition at line 28 of file main.cpp.

29 {
30 if ((int)s.length() != (int)t.length())
31 return false;
32 map<char, int> dictionary = {};
33 for (char el: s)
34 {
35 if (dictionary.find(el) != dictionary.end())
36 dictionary[el]++;
37 else
38 dictionary.insert(pair<char, int>{el, 1});
39 }
40 // for (pair<char, int> pair: dictionary)
41 // cout << "Char: " << pair.first << "; Count: " << pair.second << endl;
42 for (char el: t)
43 {
44 if (dictionary.find(el) != dictionary.end())
45 dictionary[el]--;
46 else
47 return false;
48 }
49 for (pair<char, int> pair: dictionary)
50 if (pair.second != 0)
51 return false;
52 return true;
53 }

Referenced by main().


The documentation for this class was generated from the following file: