-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisAnagram.cpp
More file actions
44 lines (34 loc) · 816 Bytes
/
isAnagram.cpp
File metadata and controls
44 lines (34 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution {
public:
bool isAnagram(string a, string b) {
if (a.length() != b.length()) return false;
map<char, int> charCount;
for (char c : a) {
charCount[c]++;
}
for (char c : b) {
charCount[c]--;
if (charCount[c] < 0) return false;
}
return true;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
string c, d;
cin >> c >> d;
Solution obj;
if (obj.isAnagram(c, d))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
// } Driver Code Ends