# 242. Valid Anagram

## 1.問題

* 給予字串s, t, 決定t是否是s的重新排序字

![](/files/-LJDOUZH_JFQEB3hANQ9)

## 2.想法

* 紀錄每個字元出現的次數

## 3.程式碼

```
class Solution {
public:
    bool isAnagram(string s, string t) {
        int size1 = s.size();
        int size2 = t.size();
        if (size1 == 0 && size2 ==0)
        {
            return true;
        }
        vector<int> cnt1(128, 0);
        vector<int> cnt2(128, 0);
        for (int i = 0; i < size1; i++)
        {
            cnt1[s[i]]++;
        }
        for (int i = 0; i < size2; i++)
        {
            cnt2[t[i]]++;
        }
        for (int i = 0; i < 128; i++)
        {
            if (cnt1[i] != cnt2[i])
            {
                return false;
            }
        }
        return true;
    }
};
```

## 4.Performance

![](/files/-LJDOkWNLlzi5mQCU565)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jenhsuan.gitbook.io/algorithm/leetcode/242.-valid-anagram.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
