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: ...
随机推荐
- C 中结构体对齐
参考 百度百科内存对齐 对齐作用 可以使得以最少的次数将操作数加载到寄存器中,如果数据没有对齐,则当CPU以最小读取数据大小从内存读入数据时可能只取到了一部分数据,而对齐情况下可以一次读入. 对齐修改 ...
- document.head.appendChild(element) 在 IE8 及以下报错
问题: 在开发中会遇到动态添加 script 标签的情况. 代码如下: var oScript = document.createElement('script'); oScript.src = 'd ...
- 【读书笔记】iOS-自动布局
自动布局是一项强大的功能,它允许开发者创建一个单一的用户界面,它会自动调整屏幕大小,方向和本地化,Xcode5中的编辑界面的自动布局功能已经大大增强了.当约束缺失或错误配置时,界面生成器可以修复布局. ...
- longing加载中实例
利用图片播放 <div class="wrap" id="wrap" style="position: inherit; height: 604 ...
- 微信小程序< 3 > ~ 微信小程序开源项目合集
简介 移动开发者想学习微信小程序需要学习一点HTML ,CSS和JS才能够比较快速的上手,参考自己学习Android学习过程,阅读源码是一个很好的方式,所以才收集了一些WeApp的开源项目. awes ...
- C语言中数据类型的本质
数据类型可以理解为固定内存大小的别名.比如int类型,就是表示占用4字节的内存. 1 数据类型的大小 用sizeof操作符获得数据类型的大小. 比如 int a[5]; sizeof(a)就可以得 ...
- Web Api通过文件流下载文件到本地实例
最近项目里面需要和C++的客户端互动,其中一个接口就是需要提供文件下载的接口,保证C++项目调用这个接口的时候能够正常下载文件到本地.参考了一下网上的代码,其原理就是读取服务器上指定路径的文件流,并将 ...
- Sql Server中的游标最好只用于有主键或唯一键的表
游标cursor,我想大多数人都在sql server里面用过.当一个表数据量不太大的时候,游标还是可以用的,毕竟游标是循环一个表中每一行数据的最简便办法.但是如果你用一个游标去循环一个没有主键或唯一 ...
- Angular-1.6 路由 简单使用
index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- Cisco HSRP 配置方法(热备份路由协议)配置实例
转裁于51CTO.http://www.mamicode.com/info-detail-862350.html HSRP----热备份路由协议 思科私有协议,与VRRP 虚拟路由协议 相近,(国际标 ...