Leetcode - Valid Anagram
来源:互联网 发布:其他国家的顶级域名 编辑:程序博客网 时间:2024/06/06 11:38
Question
Given two strings s and t, write a function to determine if t is an anagram of s.
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?
Java Code
//使用数组记录字符串中各个字符出现的次数,数组的索引对应字符的ASCII码public boolean isAnagram(String s, String t) { int len = s.length(); if(len != t.length()) return false; int[] sTable = new int[128];//默认初始化为0 int[] tTable = new int[128]; for(int i = 0; i < len; ++i) { sTable[s.charAt(i)]++; tTable[t.charAt(i)]++; } for(int i = 0; i < len; ++i) { if(sTable[i] != tTable[i]) return false; } return true;}
0 0
- Leetcode #242 Valid Anagram
- leetcode-242-Valid Anagram
- Leetcode: Valid Anagram
- 【leetCode】Valid Anagram
- [leetcode] 242.Valid Anagram
- leetcode 242: Valid Anagram
- 【leetcode】Valid Anagram
- [leetcode] Valid Anagram
- LeetCode Valid Anagram
- 【LeetCode】242 Valid Anagram
- [LeetCode] Valid Anagram
- leetcode: Valid Anagram
- leetCode(53):Valid Anagram
- leetcode Valid Anagram 异位体
- [leetcode 242]Valid Anagram
- leetcode Valid Anagram
- leetCode #242 Valid Anagram
- LeetCode题解:Valid Anagram
- @Register指令
- CGI-BIN目录
- MyBatis学习总结(七)——Mybatis缓存
- SysV Runlevels与systemd Targets的对比
- Activity之间参数传递方式
- Leetcode - Valid Anagram
- Android开发环境搭建
- 什么是沙盒模型?哪些操作是属于私有api范畴?
- 计算 S=1+2×3+3×4+4×5+…+N( N+1),直到 N( N+1)项大于 200 为止。
- Android技术积累:图片缓存管理
- 开源数据库中间件:Kingshard
- flot - jQuery 图表插件(jquery.flot)使用
- 解决Cordova开发的iOS的app界面被状态栏覆盖
- 工作流概念