首页 > 其他 > 详细

LeetCode OJ:Valid Anagram(有效字谜问题)

时间:2015-10-17 12:11:15      阅读:196      评论:0      收藏:0      [点我收藏+]

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.

题目的意思就是是否两个字符串之间可以通过颠倒次序来实现:

 1 class Solution {
 2 public:
 3     bool isAnagram(string s, string t) {
 4         int szS = s.size();
 5         int szT = t.size();
 6         if (szS != szT)return false;
 7         sort(s.begin(), s.end());
 8         sort(t.begin(), t.end());
 9         for(int i = 0; i < szS; ++i){
10             if (s[i] != t[i])
11                 return false;
12         }
13         return true;
14     }
15 };

 

LeetCode OJ:Valid Anagram(有效字谜问题)

原文:http://www.cnblogs.com/-wang-cheng/p/4887148.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!