LeetCode 242 Valid Anagram 解题报告
题目要求
Given two strings s and t , write a function to determine if t is an anagram of s.
题目分析及思路
给出两个字符串s和t,要求判断t是否是s的一个anagram,即由相同的字母且不同的字母顺序组成。可以使用collections.Counter统计每个字符串中不同字母的的个数,若两个字符串中的字母种类和个数都相等,则可判定t是s的一个anagram。
python代码
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
c1 = collections.Counter(s)
c2 = collections.Counter(t)
if c1 == c2:
return True
else:
return False
LeetCode 242 Valid Anagram 解题报告的更多相关文章
- 【LeetCode】242. Valid Anagram 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 字典统计词频 排序 日期 [LeetCode] 题目地址:ht ...
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- LN : leetcode 242 Valid Anagram
lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...
- [leetcode]242. Valid Anagram验证变位词
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...
- Java [Leetcode 242]Valid Anagram
题目描述: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...
- LeetCode 242. Valid Anagram (验证变位词)
Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...
- [LeetCode] 242. Valid Anagram 验证变位词
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...
- LeetCode 242 Valid Anagram
Problem: Given two strings s and t, write a function to determine if t is an anagram of s. For examp ...
- (easy)LeetCode 242.Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...
随机推荐
- Exif格式分析
转载链接: http://blog.csdn.net/simonhehe/article/details/8593354 http://blog.csdn.net/lsiyun/article/det ...
- rsyslog磁盘辅助(Disk-Assisted)模式踩坑记
最近公司为方便tracing.排查, 搞全链路日志收集,而我手上的10亿+pv的动态前端服务必然在考虑之列. 之前呢. 都是运维定制的收集方式: 如上图,rsyslog push kafka, 优点嘛 ...
- poj 1426 Find The Multiple (简单搜索dfs)
题目: Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal ...
- Java_修饰符
目录 访问控制修饰符 非访问修饰符 在java中修饰符主要分为两类:++访问修饰符++和++非访问修饰符++ 访问控制修饰符 修饰符 当前类 同一包内 子孙类 其他包 其他包子孙类 public Y ...
- HDU 2196 Compute --树形dp
Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Connet Scanning
1.connect scanning with Scapy, Tools that perform Tcp scans operate by performing a full there-wa ...
- python小猪蹄儿
夜的第七章,打字机继续向前推向,微亮! 请写一个栈 class Stack: #初始化栈(列表) def __init__(self): self.items=[] #栈的大小 def size(se ...
- Kali Linux 更新源
1. Kali Linux更新源 更换更新源,命令行中执行一下命令 /etc/apt/sources.list 2 替换sources.list里面的内容 可以使用以下三个源(使用一个即可) #ka ...
- [转] NodeJS框架express的途径映射(路由)功能及控制
NodeJS框架express的路径映射(路由)功能及控制 我们知道Express是一个基于NodeJS的非常优秀的服务端开发框架,本篇CSSer将提供express框架的route和route co ...
- phonegap走起
最近phonegap已发布4.0的了..速度提升了不少,很给力.小白们可以看下如何构建phonegap开发平台. 此文将说明如何建立一个可以被vs2015打开的phonegap的项目.我还会加上ion ...