[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 ...
随机推荐
- 从0开始带你成为JVM实战高手(百度网盘)
狸猫技术窝<从0开始带你成为JVM实战高手> 之前写过几篇 JVM 相关的文章,最近复盘的时候,发现狸猫技术窝<从0开始带你成为JVM实战高手>真的不错,然后就在网上找了一下( ...
- Spring Boot系列 八、集成Kafka
一.引入依赖 <dependency> <groupId>org.springframework.kafka</groupId> <artifactId> ...
- day8(使用celery异步发送短信)
1.1在celery_task/mian.py中添加发送短信函数 # celery项目中的所有导包地址, 都是以CELERY_BASE_DIR为基准设定. # 执行celery命令时, 也需要进入CE ...
- moviepy用VideoFileClip加载视频时报UnicodeDecodeError: utf-8 codec cant decode byte invalid start byte错误
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 使用moviepy用: clip1 = Video ...
- 第12.7节 Python标准库内置模块小结
本章老猿走马观花般的介绍了一下前面没有介绍的内置模块,内容很多,介绍的很泛,介绍的目的只是让大家知道有哪些内置模块.大致的功能有哪些,以后要使用时大家可以再去详细研究.之所以采用这种方式,一是老猿时间 ...
- 第15.6节 PyQt5安装与配置
一. 引言 关于PyQt5的安装网上有很多的文章,老猿也是学习了好多,最后结合其他模块安装的知识发现其实安装很简单,就是直接使用pip或pip3安装就可以了,这样既无需预先下载好软件,也无需担心版本的 ...
- PyQt(Python+Qt)学习随笔:QAbstractItemView的defaultDropAction属性
老猿Python博文目录 老猿Python博客地址# 一.概述 defaultDropAction属性用于控制QAbstractItemView及其子类的实例视图中拖放时放下的默认操作.该属性的类型为 ...
- 步步为营,打造CQUILib UI框架库
步步为营,打造CQUILib UI框架库 UI框架包括如下几个方面:: 丰富的UI控件 窗口管理 主题 多语言 托盘 视图与业务解耦 登录框效果如下:: 提示框效果如下:: 后续讲解如何步步为营,打造 ...
- Codeforces Edu Round 65 A-E
A. Telephone Number 跟之前有一道必胜策略是一样的,\(n - 10\)位之前的数存在\(8\)即可. #include <iostream> #include < ...
- uniapp图片转base64
直接上代码了,网上也很多一样的,这里记录下,因为仅仅第二种在真机微信小程序上我这里测试转换失败,所以就一并写在这里了: //图片转base64 urlTobase64(url){ // #ifdef ...