CareerCup 1.3
2013-03-21 13:28
274 查看
1.3 Given two strings, write a method to decide if one is a permutation of the other.
Solution 1:
Solution 2:
Solution 1:
bool isPermutation(string a, string b) { if (a.length() != b.length()) return false; sort(a.begin(), a.end()); sort(b.begin(), b.end()); return a == b; }
Solution 2:
bool isPermutation(string a, string b) { if (a.length() != b.length()) return false; vector<int> c(256, 0); for (int i = 0; i < a.length(); i++) c[a[i]]++; for (int i = 0; i < b.length(); i++) { c[b[i]]--; if (c[b[i]] < 0) return false; } return true; }
相关文章推荐
- careercup1.3: remove duplicate without extra space.
- careercup1.3: remove duplicate without extra space.
- CareerCup All in One 题目汇总 (未完待续...)
- careercup4.2
- Recursion 计算表达式的括号组合 @CareerCup
- Sorting_Searching 叠罗汉 @CareerCup
- Moderate rand5()产生rand7() @CareerCup
- Hard 大文本找两个单词最短距离 @CareerCup
- Arrays_Strings 判断两个字符串是否有相同的字符 @CareerCup
- Stack_Queue 一个数组实现三个栈 @CareerCup
- CareerCup An in-place algorithm for String Transformation
- CareerCup之1.7 Set Matrix Zeroes
- Careercup Facebook Keep the number beautiful...
- careercup-C和C++ 13.4
- 奋笔疾书C++之CareerCup——面试前期准备
- CareerCup.Cracking.the.Technical.Interview summaries
- CareerCup 1.5
- careercup5.5求解转换两数所需修改的位数
- Recursion 爬楼梯问题 @CareerCup
- Moderate 找到数组中和为定值的整数对 @CareerCup