【LeetCode】242 - 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.
Anagram:Only change the arrangement of the word, but the variety and number of chars in the word are identical.
Solution 1: #include<algorithm> sort
class Solution {
public:
bool isAnagram(string s, string t) { //runtime:76ms
sort(s.begin(),s.end());
sort(t.begin(),t.end());
return s==t;
}
};
Solution 2: count
class Solution {
public:
bool isAnagram(string s, string t) { //runtime:12ms
vector<int> count(,);
for(int i=;i<s.size();i++)
count[s[i]-'a']++;
for(int i=;i<t.size();i++)
count[t[i]-'a']--;
for(int i=;i<;i++)
if(count[i]!=)
return false;
return true;
}
};
【LeetCode】242 - Valid Anagram的更多相关文章
- 【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 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 字典统计词频 排序 日期 [LeetCode] 题目地址:ht ...
- 【一天一道LeetCode】#242. Valid Anagram
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- 【LeetCode】760. Find Anagram Mappings 解题报告
[LeetCode]760. Find Anagram Mappings 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/find ...
- 【LeetCode】36. Valid Sudoku 解题报告(Python)
[LeetCode]36. Valid Sudoku 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址 ...
- 【LeetCode】593. Valid Square 解题报告(Python)
[LeetCode]593. Valid Square 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...
- 【LeetCode】678. Valid Parenthesis String 解题报告(Python)
[LeetCode]678. Valid Parenthesis String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人 ...
- 【LeetCode】65. Valid Number
Difficulty: Hard More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...
- 【LeetCode】680. Valid Palindrome II
Difficulty:easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/valid-palindrome ...
随机推荐
- SSIS ->> Logging
SSIS提供了Event Handler之外的另一种方法捕捉Event和获取需要的信息,这种方法是Logging.SSIS的Logging针对不同的组件可以提供比Event Handler更多的Eve ...
- Backbone seajs demo2
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- linux 配置 wlan 连接
第一步,先确定你已经安装了无线网卡驱动.我的是 ath9k ,linux 内核不自带,现编译成模块 然后安装上.具体步骤请自行搜索 linux 编译内核 第二步,起用模块 modprobe ath9k ...
- Android之开发杂记(三)
一.popup 弹出框 在onCreate中创建时异常 Unable to add window -- token null is not valid; is your activity runnin ...
- Google 镜像站大集合
没有了google的日子是相当难受,下面推荐一些google的镜像站,感谢原文博主的无私奉献,同时也欢迎大家总结科研上的小技巧,心得等来本平台投稿,好东西当然要拿出来共同分享! 以下镜像站分原版和非原 ...
- Lucene学习笔记(更新)
1.Lucene学习笔记 http://www.cnblogs.com/hanganglin/articles/3453415.html
- LA 3902 Network
人生第一道图论题啊,有木有 题意: 有一个树状网络,有一个原始服务器s,它的服务范围是k 问至少再放多少台服务范围是k的服务器才能使网络中的每个节点都被覆盖掉 解法: 我们以原始服务器为根将其转化成一 ...
- 51nod1354 选数字
01背包tle. 解题报告(by System Message) 类似于背包的DP,以乘积为状态.先把等选数字里面不是K约数的去掉.然后找出K的约数,进行离散化.然后dp[i][j]表示前i个数字乘积 ...
- 编译busybox错误
为了制作一个文件系统,首先要用busybox编译出文件系统所需要的应用程序.在下载了busybox-1.13.0.tar.bz2后,编译出现如下错误: In file included from /o ...
- Linux下安装Android Studio(ubuntu)
一. 安装Android Studio 1. 添加源,按回车键继续 sudo apt-add-repository ppa:paolorotolo/android-studio 2. 更新源 sudo ...