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;
}
};
LeetCode242——Valid Anagram的更多相关文章
- leetcode242 Valid Anagram
lc242 Valid Anagram 直接统计每种字母出现次数即可 class Solution { public boolean isAnagram(String s, String t) { i ...
- leetcode242—Valid Anagram
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
- 【09_242】Valid Anagram
Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...
- leetcode面试准备:Valid Anagram
leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...
- 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. ...
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- 【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 ...
- [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: ...
随机推荐
- POJ_3342_Party_at_Hali-Bula
#include <iostream> #include <map> #include <cstring> using namespace std; int Gra ...
- [模式识别].(希腊)西奥多里蒂斯<第四版>笔记5之__特征选取
1,引言 有关模式识别的一个主要问题是维数灾难.我们将在第7章看到维数非常easy变得非常大. 减少维数的必要性有几方面的原因.计算复杂度是一个方面.还有一个有关分类器的泛化性能. 因此,本章的主要任 ...
- 解决 Maven was cached in the local repository, resolution will not be reattempted until the update interv
问题原因 Maven默认会使用本地缓存的库来编译工程,对于上次下载失败的库,maven会在~/.m2/repository/<group>/<artifact>/<ver ...
- jquery获取td所在的行和列
今天在做项目时.遇到一个须要获取第几行第几列的问题. 后来.网上找了找资料,整理了此文.(使用jquery的preAll()获取列) 代码例如以下: <!DOCTYPE html PUBLIC ...
- Redis学习(5)-Jedis(Java操作redis数据库技术)
Java连接redis 一,导入jar包 Redis有什么命令,Jedis就有什么方法 设置防火墙 在Linux上面运行如下代码: 单实例:Jedis实例: package com.jedis.dem ...
- pythong 中的 __call__
python __call__ (可调用对象) __call__ Python中有一个有趣的语法,只要定义类型的时候,实现__call__函数,这个类型就成为可调用的. 换句话说,我们可以把这个类型的 ...
- VC2012编译CEF3-转
原文地址:http://blog.csdn.net/tiplip/article/details/42047815 下载 代码下载:http://cefbuilds.com/,CEF 3.2556.1 ...
- [SpriteKit] 系统框架中Cocos2d-x制作小游戏ZombieConga
概述 使用SpriteKit实现一个简单的游戏, 通过一个游戏来进行SpriteKit的入门, 熟练2D游戏的API, 也可以更好的结合在iOS应用中. 详细 代码下载:http://www.demo ...
- C#基础蛋疼到爆的Byte类型表数范围之网兜毛衣见解……
事实上写这篇对Byte类型表数范围的文章,真的是蛋疼+蛋疼+蛋疼,每每看到Byte表数范围这一块.都对-128如此的陌生与迷茫.操蛋的Byte,操蛋的人生-- 熊孩子出场:Byte 恶作剧结果:表数范 ...
- ContactsContract.Contacts之sort_key
// 从Contacts表中找出所有联系人 Cursor cursor = context.getContentResolver().query( ContactsContract.C ...