Skip to content

Commit 2b08ad4

Browse files
committed
valid anagram
1 parent 33f4403 commit 2b08ad4

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Valid Anagram
3+
==============
4+
5+
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
6+
7+
Example 1:
8+
Input: s = "anagram", t = "nagaram"
9+
Output: true
10+
11+
Example 2:
12+
Input: s = "rat", t = "car"
13+
Output: false
14+
15+
Constraints:
16+
1 <= s.length, t.length <= 5 * 104
17+
s and t consist of lowercase English letters.
18+
19+
Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?
20+
*/
21+
22+
class Solution
23+
{
24+
public:
25+
bool isAnagram(string s, string t)
26+
{
27+
vector<int> arr(26, 0);
28+
for (auto &i : s)
29+
arr[i - 'a']++;
30+
for (auto &i : t)
31+
arr[i - 'a']--;
32+
for (auto &i : arr)
33+
if (i != 0)
34+
return false;
35+
return true;
36+
}
37+
};

Striver Sheet/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@
143143

144144
### Day 16 ()
145145

146-
- []() - [Cpp Soultion](./Day-16/.cpp)
147-
- []() - [Cpp Soultion](./Day-16/.cpp)
148-
- []() - [Cpp Soultion](./Day-16/.cpp)
149-
- []() - [Cpp Soultion](./Day-16/.cpp)
146+
- [Z algorithm (Linear time pattern searching Algorithm)](https://www.geeksforgeeks.org/z-algorithm-linear-time-pattern-searching-algorithm/)
147+
- [KMP Algorithm for Pattern Searching](https://www.geeksforgeeks.org/kmp-algorithm-for-pattern-searching/)
148+
- [Minimum characters to be added at front to make string palindrome](https://www.geeksforgeeks.org/minimum-characters-added-front-make-string-palindrome/)
149+
- [Valid Anagram](https://leetcode.com/problems/valid-anagram/) - [Cpp Soultion](./Day-16/Valid%20Anagram.cpp)
150150
- []() - [Cpp Soultion](./Day-16/.cpp)
151151
- []() - [Cpp Soultion](./Day-16/.cpp)
152152

0 commit comments

Comments
 (0)