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: ...
随机推荐
- NIO学习笔记五:Buffer 的使用
Java NIO中的Buffer用于和NIO通道进行交互.数据是从通道读入缓冲区,从缓冲区写入到通道中. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO Buffe ...
- python-适配器模式
源码地址:https://github.com/weilanhanf/PythonDesignPatterns 说明: 为了解决接口不兼容的问题引进一种接口的兼容机制,就是适配器模式,其通过提供一种适 ...
- js知识学习图谱,新手必看
前端新手学习也不外乎就是Html css html5 css3 这是最基本的,学会这些仅仅可以说是会写布局,写网页,不算前端开发,还有最重要的js,jq要学习,我自己java后台转前端,现在复 ...
- for循环中嵌套setTimeout,执行顺序和结果该如何理解?
这两天在捣鼓作用域的问题,有的时候知识这个东西真的有点像是牵一发而动全身的感觉.在理解作用域的时候,又看到了一道经典的面试题和例子题. 那就是在for循环中嵌套setTimeout延时,想想之前面试的 ...
- IT的2017,面临数字生态系统新挑战,该怎么办?
所谓数字生态系统,就是包含一系列基于标准,规模可变的硬件.软件.数字设备和服务,可系统地实现企业信息数字化,数据流通,以帮助企业提高运营效率. 随着越来越多的中国企业加入数字生态系统,中国CIO在技术 ...
- Android 常见adb命令
Android 常见adb命令 by:授客 QQ:1033553122 1. 查看所有已链接的设备 命令: adb devices 例: C:\Users\laiyu>adb device ...
- 1.print()与input()
hello world必备->print函数 print(): 作用: 打印函数,打印数据到屏幕中 参数列表: print(value, ..., sep=' ', end='\n', file ...
- 创建Filter类
1.Filter可认为是servlet的一种“加强版”,它主要用于对用户请求进行预处理,也可以对HttpServletresponse进行后处理,是个典型的处理链.Filter也可对用户请求生成响应, ...
- AWS CSAA -- 04 AWS Object Storage and CDN - S3 Glacier and CloudFront(一)
013 S3 - 101 014 Create an S3 Bucket - Lab
- Linux下查看端口,强制kill进程
1.查看8088端口被哪个进程占用:netstat -apn | grep 8088 2.强制kill某一进程:kill -s 9 1827