Cracking the Coding Interview Q1.3
2014-07-03 09:34
211 查看
Write a method to decide if two strings are anagrams or not.
View Code
public static boolean permutation(String s, String t) { if (s.length() != t.length()) { return false; } int[] letters = new int[256]; char[] s_array = s.toCharArray(); for (char c : s_array) { // count number of each char in s. letters[c]++; } for (int i = 0; i < t.length(); i++) { int c = (int) t.charAt(i); if (--letters[c] < 0) { return false; } } return true; }
View Code
相关文章推荐
- cracking the coding interview No1.3
- Cracking The Coding Interview 1.3
- cracking the coding interview problem solution 1.3
- Cracking The Coding Interview 3rd -- 1.3
- 判断一个二叉树是否是平衡二叉树 Cracking the coding interview 4.1
- Cracking The Coding Interview 1.6
- Cracking The Coding Interview3.4 暂存
- Cracking coding interview(1.3)去掉字符串中重复字符
- Cracking the coding interview--Q3.2
- Cracking the coding interview--Q2.2
- Cracking the coding interview--Q3.1
- Cracking the coding interview--Q3.2
- 《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目6
- Cracking the coding interview--Q4.1
- 《Cracking the Coding Interview》——第14章:Java——题目1
- Cracking the coding interview--Q20.13
- 《Cracking the Coding Interview》——第17章:普通题——题目9
- 《Cracking the Coding Interview》——第18章:难题——题目9
- Cracking The Coding Interview 3rd -- 1.4
- Cracking the Coding Interview(Stacks and Queues)