当前位置:网站首页>242. valid Letter heteronyms
242. valid Letter heteronyms
2022-07-01 03:43:00 【Sun_ Sky_ Sea】
242. Effective alphabetic words
Original title link :https://leetcode.cn/problems/valid-anagram/
Given two strings s and t , Write a function to determine t Whether it is s Letter heteronym of .
Be careful : if s and t Each character in the has the same number of occurrences , said s and t They are mutually alphabetic words .
Example 1:
Input : s = “anagram”, t = “nagaram”
Output : true
Example 2:
Input : s = “rat”, t = “car”
Output : false
Tips :
1 <= s.length, t.length <= 5 * 104
s and t Only lowercase letters
Their thinking :
Count the number of characters in the string , In the dictionary , Then judge whether the dictionaries are the same .
Code implementation :
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
边栏推荐
- Explain spark operation mode in detail (local+standalone+yarn)
- 【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
- 【伸手党福利】开发人员重装系统顺序
- The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
- Implement pow (x, n) function
- [TA frost wolf \u may - "hundred people plan"] 2.1 color space
- Home online shopping project
- FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)
- 不用加减乘除实现加法
- Leetcode:829. Sum of continuous integers
猜你喜欢

Listener listener

Leetcode 128 longest continuous sequence (hash set)

Learning notes for introduction to C language multithreaded programming

Addition without addition, subtraction, multiplication and division

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

ASGNet论文和代码解读2

Avalanche problem and the use of sentinel

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

完全背包问题

【TA-霜狼_may-《百人计划》】2.3 常用函数介绍
随机推荐
389. 找不同
不用加减乘除实现加法
BluePrism注册下载并安装-RPA第一章
8. 字符串转换整数 (atoi)
整合阿里云短信的问题:无法从静态上下文中引用非静态方法
318. 最大单词长度乘积
Appium自动化测试基础--补充:C/S架构和B/S架构说明
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
SEM of C language_ Tvariable type
FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
Pytorch training deep learning network settings CUDA specified GPU visible
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
[TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
用小程序的技术优势发展产业互联网
Ouc2021 autumn - Software Engineering - end of term (recall version)
Ridge regression and lasso regression
pytorch训练深度学习网络设置cuda指定的GPU可见
Blueprism registration, download and install -rpa Chapter 1
Appium自动化测试基础 — APPium基本原理