242. Valid Anagram
来源:互联网 发布:c语言的就业前景 编辑:程序博客网 时间:2024/06/01 08:34
题目
Given two strings s and t, write a function to determine ift 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.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
我的解法
public class Solution { public boolean isAnagram(String s, String t) { if(s.length() != t.length()) return false; int[] arr = new int[26]; // 若两字符串为回文,则最终数组元素全为0 for(char c : s.toCharArray()) arr[c - 'a'] += 1; for(char c : t.toCharArray()) arr[c - 'a'] -= 1; for(int n : arr) if(n != 0) return false; return true; }}
0 0
- [leetcode] 242.Valid Anagram
- 242.Valid Anagram
- leetcode 242. Valid Anagram
- 242. Valid Anagram
- [leetcode] 242. Valid Anagram
- leetCode 242. Valid Anagram
- Leetcode 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram LeetCode
- 242. Valid Anagram
- LeetCode 242. Valid Anagram
- LeetCode 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 用PyInstaller将python转成可执行文件exe笔记
- Android屏幕分辨率,颜色、像素的使用(技巧)(必看)
- Redis三种启动方式
- 【录教程必备】推荐几款屏幕录制工具(可录制GIF)
- 记录有点意思的网站
- 242. Valid Anagram
- C++ std::vector元素的内存分配问题(补充)
- 安装Server2003+SQL2000+SQL2000SP4
- missian(4)使用异步客户端
- Android直播之Vitamio的
- Linux程序源码编译安装的configure配置详解
- PAT乙级1064 朋友数
- ==和equals方法的区别以及Integer和String的应用
- RESTful架构详解