一、有效字母异位词(数组)
1、题目:
给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。
示例 1: 输入: s = "anagram", t = "nagaram" 输出: true
示例 2: 输入: s = "rat", t = "car" 输出: false
2、代码:
#include<iostream>
#include<string.h>
using namespace std;
string s, t;
class Solution {
public:
bool isAnagram(string s, string t)
{
int hash[26];
for (int i = 0; i < s.length(); i++)
{
hash[s[i] - 'a']++;
}
for (int i = 0; i < t.length(); i++)
{
hash[t[i] - 'a']--;
}
for (int i = 0; i < 26; i++)
{
if (hash[i] != 0)