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 ...
随机推荐
- 堆溢出学习笔记(linux)
本文主要是linux下堆的数据结构及堆调试.堆溢出利用的一些基础知识 首先,linux下堆的数据结构如下 /* This struct declaration is misleading (but a ...
- JAVA中的栈和堆【转】
原文链接 https://www.cnblogs.com/ibelieve618/p/6380328.html JAVA在程序运行时,在内存中划分5片空间进行数据的存储.分别是:1:寄存器.2:本地方 ...
- SQL数据插入
T-SQL中提供了多个将数据插入到表中的语句:insert values.insert select.insert exec.select into和Bulk insert: 1. insert v ...
- python基础之常用关键字总结
前言 到python3.6为止,python内置的关键字有33个,比python2.7的版本多了2个.下面总结一下python3的关键字的使用. python内置关键字 解释器在加载上下文的时候,如果 ...
- 利用CSS3实现鼠标悬停在图片上图片缓慢缩放的两种方法
1.改变background-size属性 将图片作为某个html元素的背景图片,用transition属性改变图片的大小. .container{ background-size: 100% 100 ...
- cc.Node 的坐标空间与ACTION的学习
1.创建二维的向量坐标 //创建向量坐标方法一 let new_pos1 = new cc.Vec2(100, 100); //创建向量坐标方法二 let new_pos2 = cc.v2(200, ...
- 一起学爬虫——使用Beautiful Soup爬取网页
要想学好爬虫,必须把基础打扎实,之前发布了两篇文章,分别是使用XPATH和requests爬取网页,今天的文章是学习Beautiful Soup并通过一个例子来实现如何使用Beautiful Soup ...
- js下载base64格式的图片(兼容火狐)
//下载图片 download() { let imgData = 'data:image/png;base64,iVBORw0KGgoAAAANSUh........'; this.download ...
- python接口测试-认识POST请求
上午和一个大神交流了一下,给我了一点建议:多做笔记,勤复盘:及时记录自己,最好的提升不是来自于别人,而是来自于自身.我觉得挺有道理的,分享出来.共勉 说正事. 今天把post请求的大概内容看了一下.虽 ...
- Kali Linux NetHunter教程Kali NetHunter支持的设备和ROMs
Kali Linux NetHunter教程Kali NetHunter支持的设备和ROMs NetHunter是一个基于Kali Linux为Nexus设备构建的Android渗透测试平台,其中包括 ...