leetcdoe Valid Anagram
题目连接
https://leetcode.com/problems/valid-anagram/
Valid Anagram
Description
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) {
int A[26] = { 0 }, B[26] = { 0 };
size_t i, n = s.length(), m = t.length();
if (n != m) return false;
for (i = 0; i < n; i++) A[s[i] - 'a']++;
for (i = 0; i < m; i++) B[t[i] - 'a']++;
for (i = 0; i < 26; i++) {
if (A[i] != B[i]) return false;
}
return true;
}
};
leetcdoe Valid Anagram的更多相关文章
- 【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: ...
- LN : leetcode 242 Valid Anagram
lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...
- LeetCode_242. Valid Anagram
242. Valid Anagram Easy Given two strings s and t , write a function to determine if t is an anagram ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
随机推荐
- 三层架构与MVC比较:
三层架构与MVC比较: 1.两者不是同一概念 三层架构是一个分层式的软件体系架构设计,它可适用于任何一个项目. MVC是一个设计模式,它是根据项目的具体需求来决定是否适用于该项目. 那么架构跟设计模式 ...
- 创建maven parent project & module project
1.命令方式: 1)Create the top-level root: mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo.arc ...
- eclipse修改workspace
Eclipse是一款很强的Java IDE,我们在开始的时候,往往设定了默认的workspace,当用久在之后,我们可能要去更改一下workspace的位置,但是在启动的时候已经不会显示更改了.下面有 ...
- PHP判断用户是手机端?还是浏览器端访问?
function isMobile(){ $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ' ...
- 搭建 Keras
首先安装ipython ipython安装完成以后出现如下界面 然后安装theano 中途安装因为网络不好,造成超时而停止安装或者停滞不前,则按下Ctrl+C,停止此操作,或者关掉Anaconda P ...
- 为什么要用babel-polyfill
1.为什么要用babel-polyfill Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如 Iterator.Generator.Set.Maps.Prox ...
- js 常用排序
1. 冒泡排序 原理:从第一个元素开始,把当前元素和下一个索引元素进行比较.如果当前元素大,那么就交换位置,重复操作直到比较到最后一个元素 function bubbleSort(arr) { if ...
- Selenium IDE + Firefox
又掉进了同一个坑了,最新firefox版本和selenium ide不兼容,工具栏愣是找不到selenium ide的button,换成firefox5.0就好了 selenium用的版本是2.5. ...
- 洛谷P1655 小朋友的球(Stirling数)
P1655 小朋友的球 题目描述 @发源于 小朋友最近特别喜欢球.有一天他脑子抽了,从口袋里拿出了N个不同的球,想把它们放到M个相同的盒子里,并且要求每个盒子中至少要有一个球,他好奇有几种放法,于是尝 ...
- Spring - SpringIOC容器详解
一.什么是Spring IOC: Ioc—Inversion of Control,即“控制反转”,不是什么技术,而是一种设计思想. 在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是 ...