forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0242.cpp
More file actions
31 lines (31 loc) · 710 Bytes
/
0242.cpp
File metadata and controls
31 lines (31 loc) · 710 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
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
bool isAnagram(string s, string t)
{
if (s.size() != t.size()) return false;
int c_char[26] = { 0 };
for (int i = 0; i < s.size(); ++i)
{
++c_char[s[i] - 'a'];
--c_char[t[i] - 'a'];
}
for (int i = 0; i < 26; i++)
{
if (c_char[i] != 0) return false;
}
return true;
}
};
int main()
{
string s = "anagram";
string t = "nagaram";
cout << Solution().isAnagram(s, t) << endl;
return 0;
}