当前位置:网站首页>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
边栏推荐
- Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
- BluePrism注册下载并安装-RPA第一章
- You cannot right-click F12 to view the source code solution on the web page
- 【伸手党福利】JSONObject转String保留空字段
- Feign remote call and getaway gateway
- Filter
- 10、Scanner. Next() cannot read spaces /indexof -1
- Data exchange JSON
- Complete knapsack problem
- Idea plug-in backup table
猜你喜欢

How to achieve 0 error (s) and 0 warning (s) in keil5

Server rendering technology JSP

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

The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list

Test function in pychram

Binary tree god level traversal: Morris traversal

Implement pow (x, n) function

FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)

访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载

pytorch训练深度学习网络设置cuda指定的GPU可见
随机推荐
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
Thread data sharing and security -threadlocal
idea插件备份表
go实现命令行的工具cli
JS daily development tips (continuous update)
C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
Appium fundamentals of automated testing - basic principles of appium
整合阿里云短信的问题:无法从静态上下文中引用非静态方法
二叉树神级遍历:Morris遍历
GCC usage, makefile summary
10、Scanner.next() 无法读取空格/indexOf -1
IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
Edlines: a real time line segment detector with a false detection control
Md5sum operation
Detailed explanation of ES6 deconstruction grammar
LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表
Bilinear upsampling and f.upsample in pytorch_ bilinear
网页不能右键 F12 查看源代码解决方案
FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)