242. Valid Anagram
来源:互联网 发布:淘宝网m 编辑:程序博客网 时间:2024/06/05 04:31
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 len_s = s.length(); int len_t = t.length(); if(len_s != len_t){ return false; } vector<int> count(26, 0); for(int i =0; i < len_s; i++){ count[s[i] - 'a']++; } for(int i = 0; i < len_t; i++){ if( --count[t[i]-'a']<0 ) { return false; } } return true; }};
0 0
- [leetcode] 242.Valid Anagram
- 242.Valid Anagram
- leetcode 242. Valid Anagram
- 242. Valid Anagram
- [leetcode] 242. Valid Anagram
- leetCode 242. Valid Anagram
- Leetcode 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram LeetCode
- 242. Valid Anagram
- LeetCode 242. Valid Anagram
- LeetCode 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- Android Fragment学习小结
- nginx反向代理实例
- JMS简介与ActiveMQ实战
- 反射是什么,以及作用
- php 去除字符串首尾的空格
- 242. Valid Anagram
- 项目第一天,看框架
- spring中 Controller, Service , Component, Repository注解说明
- OO in Perl5
- 找出一个整数数组中第二大的数
- Weekly Roundup: Basketball
- Win32环境下代码注入与API钩子的实现
- jQuery如何追加tr到table中?
- unity导入模型无色