[LC] 242. 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?
class Solution {
public boolean isAnagram(String s, String t) {
if (s.length() != t.length()) {
return false;
}
char[] charArr = new char[26];
for (int i = 0; i < s.length(); i++) {
charArr[s.charAt(i) - 'a'] += 1;
charArr[t.charAt(i) - 'a'] -= 1;
}
for (char ch : charArr) {
if (ch != 0) {
return false;
}
}
return true;
}
}
[LC] 242. Valid Anagram的更多相关文章
- 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 ...
- 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: ...
- 242. Valid Anagram 两个串的最基础版本
[抄题]: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...
- 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 ...
- 【leetcode❤python】242. Valid Anagram
class Solution(object): def isAnagram(self, s, t): if sorted(list(s.lower()))==sorted(list ...
- 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...
随机推荐
- OA|DOAJ|Highwire press|Springeropen|Plos journal|电子印本|中国科技论文在线|arxiv|chinaxiv|MIT机构知识库|中科院机构知识库|Email alert|Citeseer|RSS|F1000 prime
信息检索 OA:open access开放获取 金色OA:出版社主导, 开放出版,全部都可以下载. 开放论文:只有部分可以下载. 绿色OA:作者主导,发表后放在机构知识库中,排版不同,但是内容一致.E ...
- keras_yolo3程序框架理解
- java android环境变量配置
JAVA_HOME 用于jdk配置D:\Program Files\Java\jdk1.8.0_25 path %JAVA_HOME%\bin;;%JAVA_HOME%\jre\bin;;D:\P ...
- 第 36 章 TCP/IP协议基础
问题一:为什么要有缓存表?为什么表项要有过期时间而不是一直有效 1.参考网址: 1)网络——ARP协议 2)linux arp机制解析 2.解答: 2.1 ARP缓存可以减小广播量,当主机发送一个AR ...
- Java 14 有哪些新特性?
记录为 Java 提供了一种正确实现数据类的能力,不再需要为实现数据类而编写冗长的代码.下面就来看看 Java 14 中的记录有哪些新特性. 作者 | Nathan Esquenazi 译者 | 弯月 ...
- 2×c列联表|多组比例简式|卡方检验|χ2检验与连续型资料假设检验
第四章 χ2检验 χ2检验与连续型资料假设检验的区别? 卡方检验的假设检验是什么? 理论值等于实际值 何条件下卡方检验的需要矫正?如何矫正? 卡方检验的自由度如何计算? Df=k-1而不是n-1 卡方 ...
- console.log和alert的区别
alert是同步的,如果不关闭弹出框,js代码就不会继续执行下去,这时候浏览器啥都干不了. console.log不会打断js的执行. 当要输出几十几百条信息的时候还是得用console.log,而且 ...
- 关于luoguU67856 数列一题
本题采用累加法 首先这个式子\[a_n = ka_{n-1}+b\]的通项不用我说了吧 然后就是累加法 \[S_n = \sum_{i=1}^{n} a_i = \sum_{i=1}^{n} ka_{ ...
- 人工智能必备之Python3.8.1-安装
1_下载Python 2_下载Python 3_下载Python 4_下载Python-选这里下载:Windows x86-64 executable installer 5_安装Python 6.自 ...
- 如何选择开源项目的license
https://choosealicense.com/ http://www.csdn.net/article/2013-07-16/2816249-Github-Open-Source-Licens ...