242. Valid Anagram

xiaoxiao2021-02-28  81

原题

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.

代码实现

public bool IsAnagram(string s, string t) { int[] hash = new int[123]; //a~z if(s.Length!=t.Length) return false; foreach(var ch in s){ hash[Convert.ToInt32(ch)]++; } foreach(var ch in t){ if(hash[Convert.ToInt32(ch)]--<=0) return false; } return true; }

leetcode-solution库

leetcode算法题目解决方案每天更新在github库中,欢迎感兴趣的朋友加入进来,也欢迎star,或pull request。https://github.com/jackzhenguo/leetcode-csharp

转载请注明原文地址: https://www.6miu.com/read-81682.html

最新回复(0)