Given two strings s and , 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的更多相关文章

  1. 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 ...

  2. 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. ...

  3. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  4. 【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 ...

  5. [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: ...

  6. 242. Valid Anagram 两个串的最基础版本

    [抄题]: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...

  7. 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 ...

  8. 【leetcode❤python】242. Valid Anagram

    class Solution(object):    def isAnagram(self, s, t):        if sorted(list(s.lower()))==sorted(list ...

  9. 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 ...

随机推荐

  1. php empty,isset,is_null判断比较(差异与异同)

    php empty,isset,is_null判断比较(差异与异同) 作者: 字体:[增加 减小] 类型:转载 做php开发时候,想必在使用:empty,isset,is_null 这几个函数时候,遇 ...

  2. bugs开发异常解决方法

    1.      前提 第一层:遇到异常首先必须告诉自己,冷静,不要慌.(一看到Bug就心慌,那么就不能释放必杀技) 2.      入门级 第二层:遇到Bug,第一潜意识看输出异常的信息的(控制台输出 ...

  3. 操作实践,git本地分支执行rebase,让主干分支记录更简洁

    声明:迁移自本人CSDN博客https://blog.csdn.net/u013365635 我们平时在写代码的时候,难免会修修改改,如果团队中每个人的代码提交记录都包含着一堆中间过程,是很不利于团队 ...

  4. 关于PIL库Image模块的一些测试代码

    为了加深理解,写了一些代码测试,在这里记录一下吧: 关于图片的模式问题,之前做过笔记,有“1”,“L”,"P","RGB","RGBA",& ...

  5. HNOI2018/AHOI2018 游戏

    这题放过了暴力其实就没啥意思了 虽然暴力复杂度很玄学,但是思维水平确实没啥 Description link 题意概述:现在有一条长度为 \(n\) 的链,有些边是有限制的 限制为能到某个点,才能经过 ...

  6. 别了JetBrains,换Visual Studio

    Visual Studio一直是我排斥的,这么多年一致不用. 2019年JetBrains的注册码越来越频繁的被封杀,我承认使用盗版不对. 试过Eclipse+pydev搞python,但是todo用 ...

  7. Java连接MySQL Warning: Establishing SSL connection without server's identity verification is not recommended

    1. 数据库 1.1 创建表 在当前数据库students中,创建数据表student: mysql> create table student( ),#学生ID ),#学生姓名 -> a ...

  8. ubuntu下Django的搭建

    工具:Window下的pycharm .VirtualBox下的Ubuntu系统.非必需的Xshell(远程连接工具) 现在针对各种包或python版本不能共存或包不能很好下载的问题,开始流行使用虚拟 ...

  9. python-day7爬虫基础之Ajax数据爬取

    前几天一直在忙老师的项目,就没有继续学python,也没有写什么收获,今天晚上有空看看书,边看边理解着写吧: 首先说一下,我对Ajax的理解,就是有时候我们在浏览某个网页的时候,只要我们鼠标一直往下滑 ...

  10. rabbitmq安装(linux)遇到 很多坑

    1.下载erlang官网地址 http://www.erlang.org/download 挑选合适的版本 然后 建议20.3运行命令 wget http://erlang.org/download/ ...