Easy 242题 Valid Anagram
来源:互联网 发布:matalab y引入数据 编辑:程序博客网 时间:2024/05/01 05:47
Question:
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.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
Solution:
public class Solution { public boolean isAnagram(String s, String t) { int slen=s.length(); int tlen=t.length(); if(slen!=tlen) return false; int[] map = new int[26]; for(int i=0;i<=slen-1;i++) map[s.charAt(i)-'a']++; for(int i=0;i<=tlen-1;i++) map[t.charAt(i)-'a']--; for(int i=0;i<=25;i++) if(map[i]!=0) return false; return true; }}
0 0
- Easy 242题 Valid Anagram
- [Leetcode 242, Easy] Valid Anagram
- 【LeetCode】(242)Valid Anagram(Easy)
- leetcode 242[easy]----Valid Anagram
- 【Leet Code】 242. Valid Anagram--easy
- <LeetCode><Easy>242Valid Anagram (排序)
- Valid Anagram(easy)
- 242. Valid Anagram (Easy)
- 242. Valid Anagram [easy] (Python)
- 242. Valid Anagram 难度:easy
- leetcode 242 Valid Anagram(难易度:Easy)
- Easy-题目8:242. Valid Anagram
- Leetcode 242. Valid Anagram (Easy) (cpp)
- Leetcode #242 Valid Anagram
- leetcode-242-Valid Anagram
- leetcode 242: Valid Anagram
- 242-e-Valid Anagram
- 【LeetCode】242 Valid Anagram
- Unique Binary Search Trees II
- Maximum Product Subarray
- mt5 竖线,连接线 方框
- GCC 符号表小结
- Longest Increasing Subsequence
- Easy 242题 Valid Anagram
- Python的执行模型(Execution Model)
- 大学感悟【六】
- Longest Common Subsequence
- LIN 总线的一些细节
- Easy 438题 Find All Anagrams in a String
- 关于上拉电阻+推挽/开漏
- Learning Python 021 创建文件夹、创建文件
- Learning Python 022 调用DOS命令 --- 实例:调用Windows里面的copy命令