题目要求

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. 【转】协同开发中SVN使用规范试用

    转自:http://www.cnblogs.com/BraveCheng/archive/2012/07/02/2573617.html 协同开发中SVN使用规范试用 目标,要求 本次svn提交规范主 ...

  2. RTF文件格式

    文档地址 首先给出一个生成最简单的RTF文件的脚本 f=open('hello_world.rtf','w') padding='{\\rtf1\\ansi' padding+=' Hello Wor ...

  3. 帆软报表(finereport) 复选框多值查询

    定义数据集 SELECT * FROM 库存 设计模板 设置控件:控件名称 XX  要与 单元格中 取值公式  =$XX   对应,控件值可更改 下拉复选框控件: 设置控件名称(与模板中=$选仓库  ...

  4. echarts tree 树型图层级距离设置

    网上找了半天,没有找到设置层级距离的属性,默认是自动适应的,无奈只能改源码,分享出来希望可以帮到有相同需求的... 上github下载echarts源码包,打开src=>chart=>tr ...

  5. 小程序 -- ui布局

    Flex布局 相对定位和绝对定位 弹性盒模型 display flex-direction flex-wrap  :nowrap(不换行)/ wrap(换行,第一行在上方)/ wrap-reverse ...

  6. JavaScript 动态选择方法和属性

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  7. nginx+vsftp图片下载java代码上传

    系统环境:阿里云centos7.3 安装nginx 查看nginx进程 ps aux|grep nginx 在/usr/local/nginx/sbin/目录下 nginx启动 ./nginx 快速停 ...

  8. Prime Distance POJ - 2689 (数学 素数)

    The branch of mathematics called number theory is about properties of numbers. One of the areas that ...

  9. React实现局部刷新

    [项目结构] 流程: 入口文件 -> 路由 -> layout -> Analysi/Monitor/Workspace 1.入口文件 -> src/index.js 2.组件 ...

  10. JVM内存简单总结

    根据自己的认识,简单总结下Java中的数据存储及内存分析. Java中的内存大致可以分为三块:栈内存.堆内存.方法区内存,看图说话. 1).栈 栈(stack):栈是限定仅在表头进行插入和删除操作的线 ...