[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 ...
随机推荐
- Vue.js——4.指令 笔记
v-cloak:解决网速延迟 闪烁问题v-text=msg: 和{{}}表达式一样,没有闪烁问题,但是前后不能加别的,覆盖原本的内容 innerTextv-html=msg:innerHtml,一样可 ...
- awk 中 RS,ORS,FS,OFS 区别与联系
一,RS与ORS 1,RS是记录分隔符,默认的分隔符是\n,具体用法看下 [root@krlcgcms01 mytest]# cat test1 //测试文件 111 222 333 444 ...
- 关于图算法 & 图分析的基础知识概览
网址:https://learning.oreilly.com/library/view/graph-algorithms-/9781492060116/ 你肯定没有读过这本书,因为这本书的发布日期是 ...
- 1. rabbitmq 安装
1. ubuntu 16 18 安装 https://blog.csdn.net/haeasringnar/article/details/82715823 2. centos 7 https://w ...
- 图论中最优树问题的LINGO求解
树:连通且不含圈的无向图称为树.常用T表示.树中的边称为树枝,树中度为1的顶点称为树叶. 生成树:若T是包含图G的全部顶点的子图,它又是树,则称T是G的生成树. 最小生成树:设T=(V,E1)是赋权图 ...
- Springboot项目绑定域名,使用Nginx配置Https
一.https 简介 HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HT ...
- 17.3.12----math模块
1----math模块提供很多的数学运算功能: math.pi 圆周率 math.e 那个自然常熟就是e^x,的这个e math.ceil(i) 对i向上取整 math.floor(i) ...
- 负载均衡配置篇(Nginx)
负载均衡 == 分身的能力. 既然要有分身的能力嘛,这好办,多弄几台服务器就搞定了.今天我们讲的实例嘛…..我们还是先看图比较好: 还是图比较清晰,以下我都用别名称呼: PA : 负载均衡服务器/WE ...
- Cocoapod-终端
安装循序: Xcode->RVM->Ruby(安装过程中需要安装homebrew)->CocoaPats 参考文章: 安装地址:http://www.cnblogs.com/dagu ...
- Leetcode(104)之二叉树的最大深度
题目描述: 解题思路: 代码: public int MaxDepth(TreeNode root) { if (root == null) return 0; return Mathf.Max(Ma ...