We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ce295ce commit b82d35fCopy full SHA for b82d35f
1 file changed
valid-anagram/OstenHun.cpp
@@ -0,0 +1,35 @@
1
+/*
2
+ Given two strings s and t, return true
3
+ if t is an anagram of s, and false otherwise.
4
+
5
+ An anagram is a word or phrase formed by rearranging
6
+ the letters of a different word or phrase,
7
+ using all the original letters exactly once.
8
+*/
9
10
+#include <string>
11
+using namespace std;
12
13
+class Solution {
14
+public:
15
+ bool isAnagram(const string& s, const string& t) {
16
+ if (s.length() != t.length()) {
17
+ return false;
18
+ }
19
20
+ int freq[26] = {};
21
22
+ for (size_t i = 0; i < s.length(); i++) {
23
+ freq[s[i] - 'a']++;
24
+ freq[t[i] - 'a']--;
25
26
27
+ for (int count : freq) {
28
+ if (count != 0) {
29
30
31
32
33
+ return true;
34
35
+};
0 commit comments