ITPub博客

首页 > > > [LeetCode] Valid Anagram

[LeetCode] Valid Anagram

作者:Ruiyuan Li 时间:2015-08-03 00:00:00 0 删除 编辑

Valid Anagram

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.

Note:
You may assume the string contains only lowercase alphabets. 

解题思路:

这道题的难点在于弄清题意。字谜游戏,给定两个词,判断这两个词是否只有组成的字母顺序不一样。而后说明两个字符串只包含小写字母。于是我们可以用一个26长度的数组来计数。

class Solution {
public:
    bool isAnagram(string s, string t) {
        int len1 = s.length();
        int len2 = t.length();
        if(len1!=len2){
            return false;
        }
        vector count(26, 0);
        for(int i=0; i


转载请注明: » [LeetCode] Valid Anagram
<!-- -->

原文作者:;如有侵权,请联系管理员删除。

上一篇: [LeetCode] Gas Station
下一篇: [LeetCode] Sort Colors
请登录后发表评论 登录
全部评论

注册时间:2020-05-21

  • 博文量
    495
  • 访问量
    4826