leetcode242—Valid Anagram
Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Input: s = "anagram", t = "nagaram" Output: true
Example 2:
Input: s = "rat", t = "car" Output: false
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
想法:将字符串s和字符串t分别转成容器存储,然后按字符顺序排序。再比较两个容器是否相等。
class Solution {
public:
bool isAnagram(string s, string t) {
vector<char> st1;
vector<char> st2;
; i < s.size() ; i++){
st1.push_back(s.at(i));
}
sort(st1.begin(),st1.end());
; j < t.size() ; j++){
st2.push_back(t.at(j));
}
sort(st2.begin(),st2.end());
return st1 == st2;
}
};
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. For example, s = & ...
- 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: ...
随机推荐
- hadoop的namenode故障处理方法
Namenode 故障后,可以采用如下两种方法恢复数据. 方法一:将 SecondaryNameNode 中数据拷贝到 namenode 存储数据的目录: 方法 二: 使用 -importCheckp ...
- Linux常用基本命令( tree, pwd, cd )
pwd与cd命令 >pwd命令是“print working directory”中每个单词的首字母缩写,其功能是显示当前工作目录的绝对路径.在实际工作中,我们在命令行操作命令时,经常会在各个目 ...
- JavaScript弹出窗口方法
本文实例汇总了常用的JavaScript弹出窗口方法,供大家对比参考,希望能对大家有所帮助.详细方法如下: 1.无提示刷新网页: 大家有没有发现,有些网页,刷新的时候,会弹出一个提示窗口,点“确定”才 ...
- Code Signal_练习题_alphabeticShift
Given a string, replace each its character by the next one in the English alphabet (z would be repla ...
- CentOS7上搭建LDAP-PDC并且将windows 2008 R2加入LDAP-PDC域
由于测试原因,要涉及到将windows机器加入到ldap域,所以查看各种文档进行ldap-pdc域的搭建,并成功将windows 2008r2加入到ldap-pdc域中.下面简单记录一下搭建过程 Li ...
- java基础(十一) 枚举类型
枚举类型Enum的简介 1.什么是枚举类型 枚举类型: 就是由一组具有名的值的有限集合组成新的类型.(即新的类). 好像还是不懂,别急,咱们先来看一下 为什么要引入枚举类型 在没有引入枚举类型前,当我 ...
- 闲聊jQuery(一)
Write less, do more. 这便是jQuery的宗旨!jQuery,一个高效.精简并且功能丰富的 JavaScript 工具库. 想必,对于每一个前端开发者,一定用过jQuery吧!俗话 ...
- Resource View Window of Visual Studio
https://msdn.microsoft.com/en-us/library/d4cfawwc.aspx For the latest documentation on Visual Studio ...
- [Hive_2] Hive 的安装&配置
0. 说明 在安装好 Hadoop 集群和 ZooKeeper 分布式的基础上装好 MySQL,再进行 Hive 安装配置 1. 安装 1.1 将 Hive 安装包通过 Xftp 发送到 /home/ ...
- 网络基础之IP地址和子网掩码
IP地址 IP是英文Internet Protocol的缩写,意思是"网络之间互连的协议",也就是为计算机网络相互连接进行通信而设计的协议.在因特网中,它是能使连接到网上的所有计算 ...