[leetcode]242. Valid Anagram判断两个字符串是不是包含相同字符的重排列
/*
思路是判断26个字符在两个字符串中出现的次数是不是都一样,如果一样就返回true。
记住这个方法
*/
if (s.length()!=t.length())
return false;
int[] words = new int[26];
for (int i = 0; i < s.length(); i++) {
words[s.charAt(i)-'a']++;
words[t.charAt(i)-'a']--;
}
for (int i = 0; i < 26; i++) {
if (words[i]!=0)
return false;
}
return true;
记住这种判断两个字符是不是重排列的方法,就是判断26个字母是不是出现次数相同。
当与字符相关问题是,要记得考虑26字母hashtable
[leetcode]242. Valid Anagram判断两个字符串是不是包含相同字符的重排列的更多相关文章
- Leetcode 242 Valid Anagram 字符串处理
		
字符串s和字符串t是否异构,就是统计两个字符串的a-z的字符数量是否一值 class Solution { public: bool isAnagram(string s, string t) { ] ...
 - 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(有效的变位词)
		
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...
 - LN : leetcode 242 Valid Anagram
		
lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...
 - LeetCode 242 Valid Anagram 解题报告
		
题目要求 Given two strings s and t , write a function to determine if t is an anagram of s. 题目分析及思路 给出两个 ...
 - [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: ...
 - [google面试CTCI] 1-4.判断两个字符串是否由相同字符组成
		
[字符串与数组] Q:Write a method to decide if two strings are anagrams or not 题目:写一个算法来判断两个字符串是否为换位字符串.(换位字 ...
 - [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: ...
 - LeetCode 242 Valid Anagram
		
Problem: Given two strings s and t, write a function to determine if t is an anagram of s. For examp ...
 
随机推荐
- Alpha冲刺-第二次冲刺笔记
			
Alpha冲刺-冲刺笔记 这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE2 这个作业要求在哪里 https://edu.cnblogs. ...
 - 【NOIP2015模拟11.2晚】JZOJ8月4日提高组T2 我的天
			
[NOIP2015模拟11.2晚]JZOJ8月4日提高组T2 我的天 题目 很久很以前,有一个古老的村庄--xiba村,村子里生活着n+1个村民,但由于历届村长恐怖而且黑暗的魔法统治下,村民们各自过着 ...
 - IDEA2020.2.4最新激活教程,有效期到2089
			
前言 昨天又有好多粉丝反馈Idea失效过期,也有群里的小伙伴私聊问我,最新的Idea2020.2.4 版本要如何激活? 于是自己在网上搜罗了各种注册码.激活码,均以失败告终,有的虽然当时成功了,当时很 ...
 - 安装spyder记录
			
sudo apt-get install spyder 报错:ERROR: Could not find a version that satisfies the requirement pyqt5& ...
 - Fiddler 4 (利用Fiddler模拟恶劣网络环境)
			
1.模拟弱网环境 打开Fiddler,Rules->Performance->勾选 Simulate Modem Speeds,勾选之后访问网站会发现网络慢了很多 解决办法去掉勾选的地方网 ...
 - 第三十章、containers容器类部件QMdiArea多文档界面部件功能介绍及开发应用
			
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 一.引言 老猿在前期学习PyQt相关知识时,对每个组件的属性及方法都研 ...
 - [BJDCTF 2nd]简单注入
			
[BJDCTF 2nd]简单注入 hint.txt出现了内容. 大概意思和国赛一道题相同. username处注入\来转义单引号,password处使用sql语句整数型注入. 例如: 传入admin\ ...
 - git  常用命令 command
			
git config --list //查看配置信息 git config user.name //查看用户名 git config user.email //查看用户邮箱 从远程克隆到本地仓库 ...
 - Go语言的context包从放弃到入门
			
目录 一.Context包到底是干嘛用的 二.主协程退出通知子协程示例演示 主协程通知子协程退出 主协程通知有子协程,子协程又有多个子协程 三.Context包的核心接口和方法 context接口 e ...
 - 《Eroico》关卡与操作设计
			
操作设计: 没有给明操作教程,操作全靠蒙,只有改建的位置可以看到. 但游戏的难度并没有给玩家适应操作感,随着难度提升怪物血量增厚,但怪物并没有僵直英雄却有僵直.第一个小猫妖便给了玩家一个痛击. 方向键 ...