https://leetcode.com/problems/valid-anagram/
Question Statement:
Given two strings s and t, write a function to determine if t is an anagram of s.
For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false.
Note: You may assume the string contains only lowercase alphabets.
Solution:
Solution 1:
Get statistics map for each string and compare these two maps.
class Solution {
public:
bool isAnagram(string s, string t) {
std::unordered_map
|
Solution2:
Use an array to store statistics information.
class Solution {
public:
bool isAnagram(string s, string t) {
if (s.size() != t.size()) {
return false;
}
vector
|
No comments:
Post a Comment