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;

    }

};

LeetCode242——Valid Anagram的更多相关文章

  1. leetcode242 Valid Anagram

    lc242 Valid Anagram 直接统计每种字母出现次数即可 class Solution { public boolean isAnagram(String s, String t) { i ...

  2. leetcode242—Valid Anagram

    Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...

  3. LeetCode 242. 有效的字母异位词(Valid Anagram)

    242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...

  4. 【09_242】Valid Anagram

    Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...

  5. leetcode面试准备:Valid Anagram

    leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...

  6. 242. Valid Anagram(C++)

    242. Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. ...

  7. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  8. 【LeetCode】242. Valid Anagram (2 solutions)

    Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For ...

  9. [leetcode]242. Valid Anagram验证变位词

    Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...

随机推荐

  1. JavaScript 之 日常积累

    1. <a>标签"加入收藏",兼容IE,FireFox等 function bookmarksite() { if (window.sidebar) { // Mozi ...

  2. 天气预报的Ajax效果

    最近在网站上看了很多显示实时天气预报的,挺实用而且用户体验也不错.对用户的帮助也比较大,用户可以通过你的网站了解到实时的天气信息.感觉比较有意思,于是自己钻研了一下其中的实现方法.于是决定把代码分享给 ...

  3. Java实现根据输入的日期以及天数,获取此日期之后的天数的工作日

    public static void main(String[] args) { List<String> list = new ArrayList<String>();//节 ...

  4. ipa 打包遇到的坑

    1.xcode 打包 并上传至 appstore 审核 2.预留邮箱 收取 appstore 的审核结果 3.审核通过以后,通过 iTunes Connect 上传正式文件至 appstore     ...

  5. 检查用户输入信息是否完整(vb.net实现)

        机房收费系统中.在将用户输入的信息封装到实体中作为參数传到B层之前,总要对用户输入的信息进行检查.我将这种检查分为两类: 合法性检查 完整性检查     所谓合法性检查,就是用户输入的信息是否 ...

  6. EXCEPTION-javaBean

      CreateTime--2016年11月24日14:29:43Author:Marydon 声明:异常类文章主要是记录了我遇到的异常信息及解决方案,解决方案大部分都是百度解决的,(这里只是针对我遇 ...

  7. Eclipse 批量创建多级文件夹

      Eclipse 批量创建多级文件夹 CreateTime--2018年3月8日08:23:24 Author:Marydon 1.选中要建立文件夹的父级目录-->右键-->New--& ...

  8. Loadrunner脚本编程(2)-VuGen脚本文件的开发过程

    http://www.360doc.com/content/10/0806/13/1698198_44076570.shtml 1.定义测试项目的目标,环境,脚本,测试数据,硬件等.脚本应该符合编码规 ...

  9. TabLayout实现顶部导航(一)

    代码地址如下:http://www.demodashi.com/demo/14552.html 前言 顶部导航栏,是我们在开发中比较常见的一种显示布局,它的实现可以有多种方式,那么今天我们就来讲讲 T ...

  10. 我遇到了Hibernate异常

    真是郁闷,今天想用Hibernate的实现对数据库的增删查改,但是就是报异常不断啊!呵呵,为什么?就是在主键的问题上,我用主键的生成形式是:Sequence时就报IllegalArgumentExce ...