[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 ...
随机推荐
- CentOS7下MySQL8的二进制基本安装配置
前言 基于本地Centos7.6虚拟机Mysql8的配置(亲测有效) 一.安装前的准备 1.到官网下载mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz 2.通过Xs ...
- Python不区别字符串大小写的列表比较法
一开始想这样写,结果报了索引错误 后来改正: if user_name.lower() in [names.lower() for names in names]: 我觉得应该是in后面应该跟列表,而 ...
- RepeatSubmitInterceptor extends HandlerInterceptorAdapter
package com.ruoyi.framework.interceptor; import java.lang.reflect.Method; import javax.servlet.http. ...
- tensorflow实现sphereFace网络(20层CNN)
#coding:utf-8 import tensorflow as tf from tensorflow.python.framework import ops import numpy as np ...
- request请求生命周期
request请求生命周期 一.request请求分析 1.1. request数据请求 # views.py from rest_framework.views import APIView fro ...
- BBS项目架构实现
一.注册功能 注册页面搭建 auto_id 数据校验 使用forms组件实现(forms) 创建一个文件夹随意,创建一个.py中 在.py文件中创建类继承form.Form 创建字段实现,实现对字段的 ...
- 解决在Anaconda中的cv2在pycharm中不可使用的问题
在Anaconda中已经安装好的opencv模块在pycharm中却不能正常使用,后来发现是pycharm使用的python环境中没有opencv的包,解决方法有两种: 方法一 在pycharm的设置 ...
- 01 语言基础+高级:1-4 接口与多态_day10【接口、多态】&&day11【final、匿名内部类】
day10[接口.多态] 接口三大特征——多态引用类型转换 教学目标写出定义接口的格式写出实现接口的格式说出接口中成员的特点能够说出使用多态的前提条件理解多态的向上转型理解多态的向下转型 day10_ ...
- Vue其他指令-组件-全局-局部-组件的交互父传子
v-once指令 once:一旦,当...时候 <!DOCTYPE html> <html lang="zh"> <head> <meta ...
- Opencv笔记(一):图像的基本操作
1.图像的读.显示和保存操作 import cv2 img = cv2.imread('filename',0); cv2.imshow('name',img); k=cv2.waitKey(0); ...