当前位置:网站首页>242. 有效的字母异位词
242. 有效的字母异位词
2022-07-01 03:23:00 【Sun_Sky_Sea】
242. 有效的字母异位词
原始题目链接:https://leetcode.cn/problems/valid-anagram/
给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。
注意:若 s 和 t 中每个字符出现的次数都相同,则称 s 和 t 互为字母异位词。
示例 1:
输入: s = “anagram”, t = “nagaram”
输出: true
示例 2:
输入: s = “rat”, t = “car”
输出: false
提示:
1 <= s.length, t.length <= 5 * 104
s 和 t 仅包含小写字母
解题思路:
统计字符串的字符个数,存放在字典中,再判断字典是否一样即可。
代码实现:
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
import collections
a = collections.defaultdict(int)
b = collections.defaultdict(int)
for c in s:
a[c] += 1
for c in t:
b[c] += 1
if a == b:
return True
return False
边栏推荐
- Filter
- JUC learning
- RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
- 4、【WebGIS实战】软件操作篇——数据导入及处理
- 【伸手党福利】JSONObject转String保留空字段
- [小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation
- IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
- 数据库DDL(Data Definition Language,数据定义语言)知识点
- BluePrism注册下载并安装-RPA第一章
- multiple linear regression
猜你喜欢
Ultimate dolls 2.0 | encapsulation of cloud native delivery
Learning notes for introduction to C language multithreaded programming
Blueprism registration, download and install -rpa Chapter 1
Data exchange JSON
pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
Introduction to EtherCAT
在线公网安备案保姆级教程【伸手党福利】
Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page
IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does
C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
随机推荐
SEM of C language_ Tvariable type
Finally in promise
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
Develop industrial Internet with the technical advantages of small programs
pytorch nn.AdaptiveAvgPool2d(1)
后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动
Online public network security case nanny level tutorial [reaching out for Party welfare]
Depth first traversal of C implementation Diagram -- non recursive code
谷粒学院微信扫码登录过程记录以及bug解决
E15 solution for cx5120 controlling Huichuan is620n servo error
leetcode 1818 绝对值,排序,二分法,最大值
Leetcode:829. 连续整数求和
FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)
MFC窗口滚动条用法
10、Scanner. Next() cannot read spaces /indexof -1
二叉树神级遍历:Morris遍历
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
GCC usage, makefile summary
JUC learning
ECMAScript 6.0