当前位置:网站首页>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
边栏推荐
- Online public network security case nanny level tutorial [reaching out for Party welfare]
- 复习专栏之---消息队列
- Asgnet paper and code interpretation 2
- Edge drawing: a combined real-time edge and segment detector
- Cygwin的下载和安装配置
- How do I use Google Chrome 11's Upload Folder feature in my own code?
- E15 solution for cx5120 controlling Huichuan is620n servo error
- Pathmeasure implements loading animation
- RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
- 还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板
猜你喜欢

Appium fundamentals of automated testing - basic principles of appium

Edlines: a real time line segment detector with a false detection control

完全背包问题

SEM of C language_ Tvariable type
![[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st

Research on target recognition and tracking based on 3D laser point cloud

数据库中COMMENT关键字的使用

Explain spark operation mode in detail (local+standalone+yarn)

静态库使用MFC和共享库使用MFC的区别

不用加减乘除实现加法
随机推荐
pytorch nn.AdaptiveAvgPool2d(1)
Keil5中如何做到 0 Error(s), 0 Warning(s).
Depth first traversal of C implementation Diagram -- non recursive code
Leetcode: offer 59 - I. maximum value of sliding window
Use of comment keyword in database
在 C 中声明函数之前调用函数会发生什么?
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
Take you through a circuit board, from design to production (dry goods)
复习专栏之---消息队列
Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
Appium fundamentals of automated testing - basic principles of appium
leetcode 1818 绝对值,排序,二分法,最大值
【伸手党福利】JSONObject转String保留空字段
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
过滤器 Filter
MFC窗口滚动条用法
Thread data sharing and security -threadlocal
Research on target recognition and tracking based on 3D laser point cloud
在线公网安备案保姆级教程【伸手党福利】
md5sum操作