题目要求

Given two strings s and , 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 解题报告的更多相关文章

  1. 【LeetCode】242. Valid Anagram 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 字典统计词频 排序 日期 [LeetCode] 题目地址:ht ...

  2. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  3. 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 ...

  4. [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: ...

  5. 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, ...

  6. 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 ...

  7. [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: ...

  8. 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 ...

  9. (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 ...

随机推荐

  1. 解决只读时ios下input光标问题

    应用场景:在ios手机下对只读的input设置readonly=readonly属性还是会出现光标 解决方法: //解决ios日期光标问题 $("#Stime ,#provinceCity& ...

  2. HTTP协议09-响应首部字段

    响应首部字段 响应首部字段是由服务器向客户端返回响应报文中所使用的字段,用于补充响应的附加信息.服务器信息,以及对客户端的附加要求等信息. 1)Accept-Ranges Accept-Range:b ...

  3. 读书笔记-JavaScript高级程序设计(1)

    1.组合继承 (JavaScript 中最常用的继承模式 ) (position: page168) (书中定义了两个变量名 SuperType   SubType  乍一看 感觉不太能区分,我将改为 ...

  4. 网络编程中select模型和poll模型学习(linux)

    一.概述 并发的网络编程中不管是阻塞式IO还是非阻塞式IO,都不能很好的解决同时处理多个socket的问题.操作系统提供了复用IO模型:select和poll,帮助我们解决了这个问题.这两个函数都能够 ...

  5. 【python3 自动化基础之pip】pip常用命令归类

    1.升级pippython -m pip install --upgrade pip(包名) 2.安装pymysql pip install pymysql 3.pip按照到指定目录 python - ...

  6. 忘记加入spring-aop-4.3.16.RELEASE.jar出错

    出错代码: java.lang.NoClassDefFoundError: org/springframework/aop/framework/AopProxyUtils at org.springf ...

  7. git用代码库文件完全覆盖本地/git不能提交jar的设置

    用代码库中的文件完全覆盖本地工作版本. 方法如下: git reset --hard git pull 操作后 本地该目录下所有修改都会被删除!!! 谨慎操作! 项目目录下 文件:.gitignore ...

  8. php无限极分类方法

    仅供参考: //控制器 $data = M('category')->select(); $datas = D('Category')->_getTree($data, 0,0,TRUE) ...

  9. .net core 2.x - 日志 - to elasiticsearch

    记录日志到elasticsearch(es),下面简写es,然后我们可以通过kibana可视化的观察日志信息以及统计分析等. 1.起源 年中旬时候,公司有个需求是需要分析用户的地址,需要先分词处理然后 ...

  10. tensorflow 传入值-【老鱼学tensorflow】

    上个文章中讲述了tensorflow中如何定义变量以及如何读取变量的方式,本节主要讲述关于传入值. 变量主要用于在tensorflow系统中经常会被改变的值,而对于传入值,它只是当tensorflow ...