zoukankan      html  css  js  c++  java
  • LeetCode242——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.

    实现:
    class Solution {
    public:
        bool isAnagram(string s, string t) {
            if (s.size() != t.size()) return false;
            int bit[26] = {0}, len = s.length();
        
            for(int i=0; i<len; i++)
                bit[s[i]-'a']++;
        
            for(int i=0; i<len; i++)
                if(--bit[t[i]-'a'] < 0)
                    return false;
            return true;
        }
    };

  • 相关阅读:
    js中的字符串
    JSOP
    jq总结1
    jq总结
    诗和远方-志
    诗和远方-感
    js判断变量是否为空字符串、null、undefined
    判断js对象是否为空
    诗和远方-悟
    深复制
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/6745217.html
Copyright © 2011-2022 走看看