【Leet Code】 242. Valid Anagram--easy
来源:互联网 发布:php bindto 编辑:程序博客网 时间:2024/05/22 08:04
Given twostrings s and t, write a function to determine if t isan 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.
思路:
1) 将字符串s和t按照字母排序;
2) 比较排序后的字符串是否相同,是则返回true;否则返回false。
Tips:
借助函数std::sort()和string::compare()。
template< class RandomIt >
void sort( RandomIt first, RandomIt last );
class Solution {public: bool isAnagram(string s, string t) { int slen = s.length(); int tlen = t.length(); if(slen == 0 || tlen== 0) { if(slen == tlen) return true; else return false; } sort(s.begin(), s.end()); sort(t.begin(), t.end()); if(s.compare(t) == 0) return true; else return false; }};
0 0
- 【Leet Code】 242. Valid Anagram--easy
- Leet Code OJ 242. Valid Anagram [Difficulty: Easy]
- [Leetcode 242, Easy] Valid Anagram
- 【LeetCode】(242)Valid Anagram(Easy)
- Easy 242题 Valid Anagram
- leetcode 242[easy]----Valid Anagram
- Leet Code OJ 20. Valid Parentheses [Difficulty: Easy]
- Leet Code OJ 125. Valid Palindrome [Difficulty: Easy]
- Leet Code OJ 20. Valid Parentheses [Difficulty: Easy]
- <LeetCode><Easy>242Valid Anagram (排序)
- Valid Anagram(easy)
- 242. Valid Anagram (Easy)
- [leet code] Valid Parentheses
- [leet code] Valid Sudoku
- 242. Valid Anagram [easy] (Python)
- 242. Valid Anagram 难度:easy
- Leet Code 20 Valid Parentheses
- Leet Code OJ: Valid Number
- Android - 优化WebView页面
- 简单工厂
- awk引用shell中变量的几种方法
- HTML 七牛上传图片
- java通过一个url读取网站的源代码 储存到本地文件中
- 【Leet Code】 242. Valid Anagram--easy
- Friendship (poj 1815 最小点割集+枚举)
- docker 数据管理
- 关于echarts动态显示数据报表相关问题
- [c++基础]typedef的作用域
- 【Linux】linux常用基本命令
- 扩展欧几里得
- 分享pdf转换成html的常用方法
- 使用Inno Setup打包Winform程序