题目要求

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. Laravel 开发环境搭建 - Windows

    Laravel 开发环境搭建 - Windows  :   https://laravel-china.org/docs/laravel-development-environment/5.5/dev ...

  2. percona-toolkit 之 【pt-online-schema-change】说明【转】

    背景: MySQL 大字段的DDL操作:加减字段.索引.修改字段属性等,在5.1之前都是非常耗时耗力的,特别是会对MySQL服务产生影响.在5.1之后随着Plugin Innodb的出现在线加索引的提 ...

  3. Django-DRF-图书增删改查 !!!

      自己封装的 class MyResponse(): def __init__(self): self.status = 100 self.msg = None @property def get_ ...

  4. 资本寒冬下的android面经

    在2018年10月初,公司倒闭,无奈走上找工作的道路,不想自己平时图安逸,不思进取,再次找工作才发现,android行业也不是站在风口上,猪也能吹上天的世道了.作为技术小菜的我,再找工作那几个月真是战 ...

  5. [转]国家税务总局:个税专项附加扣除APP正式启用!(附操作指南)

    https://wallstreetcn.com/articles/3462504 12月31日国家税务总局官网消息,个人所得税专项附加扣除政策将于2019年1月1日起实施.2018年12月31日,由 ...

  6. matplotlib坐标轴设置续-【老鱼学matplotlib】

    本次会讲解如何修改坐标轴的位置. 要修改轴,就要先得到当前轴:plt.gca(),这个函数名挺怪的,其实是如下英文字母的首字母:get current axis,也就是得到当前的坐标轴. import ...

  7. spark DataFrame

    DataFrame的推出,让Spark具备了处理大规模结构化数据的能力,不仅比原有的RDD转化方式更加简单易用,而且获得了更高的计算性能.Spark能够轻松实现从MySQL到DataFrame的转化, ...

  8. 整理一下python中with的用法

    ith替代了之前在python里使用try...finally来做清理工作的方法.基本形式如下: with expression [as variable]: with-block 当expressi ...

  9. 【java】-- java并发包总结

    1.同步容器类 1.1.Vector与ArrayList异同 1.Arraylist和Vector都是采用数组方式存储数据,都允许直接序号索引元素,所以查找速度快,但是插入数据等操作涉及到数组元素移动 ...

  10. Beta(0/7)

    组长重选议题 Beta阶段计划改进完善的功能 Beta阶段计划新增的功能 需要改进的团队分工 需要改进的工具流程 Beta冲刺的时间计划安排 组长重选议题 没人想当,所以没有换. Beta阶段计划改进 ...