[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 ...
随机推荐
- 我读《DOOM启世录》——成为一个真正厉害的人
序言 谈到游戏, 你的当然会想到几乎统治游戏市场多年的英雄联盟,你可能还会想起前段时间风头大盛的王者荣耀手游,你应该还会想起正在冲击着游戏市场的"吃鸡"类型游戏. 那么, 大家是否 ...
- Linux-线程引入
1.使用进程技术的优势 (1).CPU分时复用,单核心CPU可以实现宏观上的并行 (2).实现多任务系统需求(多任务的系统是客观的) 2.进程技术的劣势 (1).进程间切换开销大 (2).进程间通信麻 ...
- share团队冲刺3
团队冲刺第三天 昨天:完成了对输出文字,按钮控件的添加,能够将其在模拟器上运行 今天:学习输入的添加方式 问题:Android resource linking failed 在改变按钮样式的时候,出 ...
- 微信支付第三方sdk使用
1.引入依赖:(对于依赖冲突自行解决) <dependency> <groupId>com.github.binarywang</groupId> <arti ...
- Spring使用Rabbitmq (简单使用)
1.pom.xml jar包引用 <dependencies> <dependency> <groupId>org.springframework</grou ...
- springboot的http监控接口启动器的配置
基于SpringBoot框架企业级应用系统开发全面实战()->03.07_http监控_recv.mp4 监控接口启动器 自定义监控接口启动器的配置 ====================== ...
- Java 14 有哪些新特性?
记录为 Java 提供了一种正确实现数据类的能力,不再需要为实现数据类而编写冗长的代码.下面就来看看 Java 14 中的记录有哪些新特性. 作者 | Nathan Esquenazi 译者 | 弯月 ...
- jq轮播图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Window RabbitMq安装
rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.它遵循Mozilla Public License开源协议,采用 Erlang 实现的工业级的消息队列(MQ)服务器,Rab ...
- redis day03 下
事务 能够有回退状态 事务命令 安命令执行没问题,redis是弱事务型 nulti incr n1 -->QUEUED(返回仅队列了) EXEC -->返回结果 pipeline 流水 ...