leetcdoe Valid Anagram

题目连接

https://leetcode.com/problems/valid-anagram/

Valid Anagram

Description

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.

class Solution {
public:
	bool isAnagram(string s, string t) {
		int A[26] = { 0 }, B[26] = { 0 };
		size_t i, n = s.length(), m = t.length();
		if (n != m) return false;
		for (i = 0; i < n; i++) A[s[i] - ‘a‘]++;
		for (i = 0; i < m; i++) B[t[i] - ‘a‘]++;
		for (i = 0; i < 26; i++) {
			if (A[i] != B[i]) return false;
		}
		return true;
	}
};
时间: 2024-10-27 18:06:14

leetcdoe Valid Anagram的相关文章

【09_242】Valid Anagram

Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Easy 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 t

【LeetCode】242. Valid Anagram (2 solutions)

Valid Anagram 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 strin

242. Valid Anagram(C++)

242. Valid Anagram 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. 题目大意: 判断两字符串含有的元素是否相同.

LeetCode:Valid Anagram

1.题目名称 Valid Anagram (易位构词) 2.题目地址 https://leetcode.com/problems/valid-anagram/ 3.题目内容 英文:Given two strings s and t, write a function to determine if t is an anagram of s. 中文:给出两个字符串,写一个函数判断t是否是s的易位构词 例如: s = "anagram", t = "nagaram",

leetCode242. Valid Anagram 合法的由颠倒字母顺序而构成的字 sort

242. Valid Anagram 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

leetcode:242 Valid Anagram-每日编程第八题

Valid Anagram Total Accepted: 42673 Total Submissions: 109227 Difficulty: Easy 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",

242题——Valid Anagram (哈希表)

Valid Anagram Total Accepted: 9718 Total Submissions: 27840My Submissions Question Solution 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 = &qu

leetcode_242——Valid Anagram (字典法)

Valid Anagram Total Accepted: 9718 Total Submissions: 27840My Submissions Question Solution 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 = &qu

[LeetCode][JavaScript]Valid Anagram

Valid Anagram 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 strin