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 ...
随机推荐
- python中列表元组字符串相互转换
python中有三个内建函数:列表,元组和字符串,他们之间的互相转换使用三个函数,str(),tuple()和list(),具体示例如下所示: >>> s = "xxxxx ...
- H.264有四种画质级别
H264相关知识-poseidonqiu-ChinaUnix博客 H.264有四种画质级别分别是BP.EP.MP.HP: 1.BP-Baseline Profile:基本画质.支持I/P 帧,只支持无 ...
- Rsync的配置与使用
一.介绍 (不想看直接可以跳过) Rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.Rsync本来是用以取代rcp的一个工具,它当前由 rsync.samba.org维护 ...
- CentOS快速搭建LAMP环境
LAMP -- Linux Apache MySQL PHP 在CentOS安装的顺序,我一般是Apache -> MySQL -> PHP 第一步.安装并配置Apache 1.使用yu ...
- Open-source Tutorial - Json.NET
JSON 简介 JSON(JavaScript Object Notation,JavaScript对象表示法)是一种由道格拉斯·克罗克福特构想和设计.轻量级的数据交换语言,该语言以易于让人阅读的文字 ...
- WPF在ViewModel中绑定按钮点击(CommandBase定义)
定义CommandBase public class CommandBase:ICommand { private readonly Action<object> _commandpara ...
- 51nod1241(连续上升子序列)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1241 题意:中文题诶- 思路:通过观察我们不难发现就是找连续 ...
- bzoj 3671: [Noi2014]随机数生成器【模拟+贪心】
降智好题 前面随机部分按照题意模拟,然后字典序贪心,也就是记录每个值的位置从1~nm依次看能不能取,能取的话更新行的取值范围(它上面的行一定取的列小于等于这个数取的列,下面行大于等于) #includ ...
- Java基础--常用API--日期相关API
一.java.util.Date 1.只用于显示系统时间,其大部分操作由Calendar代替. 格林威治时间(GMT):指的是1970年1月1日0时,不同地区有时间差. 默认输出格式:星期.月.日.时 ...
- js实现考试随机选题
考试的时候经常用到,发在这里记录一下 基本信息包括: 学号.姓名.题号.题目名称 实现原理:给每一个题目添加一个编号,JS生成随机数,遍历每一个学生,把题目根据生成的随机数作为题目编号放入学生信息中 ...