当前位置:网站首页>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
边栏推荐
- Avalanche problem and the use of sentinel
- FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)
- 过滤器 Filter
- TEC: Knowledge Graph Embedding with Triple Context
- Feign remote call and getaway gateway
- FCN全卷积网络理解及代码实现(来自pytorch官方实现)
- The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
- The value of the second servo encoder is linked to the NC virtual axis of Beifu PLC for display
- Pyramid Scene Parsing Network【PSPNet】论文阅读
- Feature Pyramid Networks for Object Detection论文理解
猜你喜欢

Idea plug-in backup table

Thread data sharing and security -threadlocal

监听器 Listener

深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)

JUC learning

Avalanche problem and the use of sentinel

RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs

二叉树神级遍历:Morris遍历

Unexpected token o in JSON at position 1 ,JSON解析问题

AfxMessageBox和MessageBox的用法
随机推荐
E15 solution for cx5120 controlling Huichuan is620n servo error
How do I use Google Chrome 11's Upload Folder feature in my own code?
数据库DDL(Data Definition Language,数据定义语言)知识点
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
Pathmeasure implements loading animation
Nacos
leetcode 1482 猜猜看啊,这道题目怎么二分?
Appium自动化测试基础 — APPium基本原理
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内
整合阿里云短信的问题:无法从静态上下文中引用非静态方法
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
Use of comment keyword in database
[reach out to Party welfare] developer reload system sequence
10、Scanner.next() 无法读取空格/indexOf -1
Finally in promise
Server rendering technology JSP
LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表
在线公网安备案保姆级教程【伸手党福利】
Leetcode:829. 连续整数求和