题目要求

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. windows配置Erlang环境

    1.说明 1.1 操作系统 win10x64 1.2 Erlang(['ə:læŋ])是一种通用的面向并发的编程语言,它由瑞典电信设备制造商爱立信所辖的CS-Lab开发,目的是创造一种可以应对大规模并 ...

  2. C++设计模式——原型模式

    什么是原型模式? 在GOF的<设计模式:可复用面向对象软件的基础>中是这样说的:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象.这这个定义中,最重要的一个词是“拷贝”,也就 ...

  3. 【easy】110. Balanced Binary Tree判断二叉树是否平衡

    判断二叉树是否平衡 a height-balanced binary tree is defined as a binary tree in which the depth of the two su ...

  4. 主席树入门——询问区间第k大pos2104,询问区间<=k的元素个数hdu4417

    poj2104找了个板子..,但是各种IO还可以进行优化 /* 找区间[l,r]第k大的数 */ #include<iostream> #include<cstring> #i ...

  5. VC调用静态库、动态库

    静态库 // 相对路径 或者 绝对路径 #include "yourlib.h" //相对路径 或者 绝对路径 #pragma comment(lib, "yourlib ...

  6. PHP开发API接口签名及验证

    <?php // 设置一个密钥(secret),只有发送方,和接收方知道 /*----发送方和接收方- start ----*/ $secret = "28c8edde3d61a041 ...

  7. java的编译过程

    用记事本编写两个java文件 第一个Employee.java import java.io.*; public class Employee{ String name; int age; Strin ...

  8. Swagger-概述

    前言 Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件.本文简单介绍了在项目中集成swagger的方法和一些常见问题.如果想深入分析项目源码,了解更多内容,见参考资料. S ...

  9. pyqt pyside QLineEdit 重写键盘事件

    pyqt pyside QLineEdit 重写键盘事件 def keyPressEvent(self, event): if (event.modifiers() & QtCore.Qt.S ...

  10. Redis自学笔记:5.实践

    第5章实践 5.3 python与redis 5.3.1安装 pip install redis 5.3.2使用方法 自己补充内容:Ubuntu下redis开启远程连接 打开redis配置:sudo ...