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 ...
随机推荐
- iOS 新建xib文件时,最外层view的约束问题
今天用在利用xib实例化view 时, 生成的view的自动布局总是用问题.具体来说,宽和高都不能和父view正确变化.仔细检查,发现下图: 注意这里右上角的Autoresizing部分,并没有设置正 ...
- verilog 仿真时读取txt文件
:]data; initial begin # clk =; clk = ~clk; end initial begin # rst=; # rst=; end :]data_sin[:]; //// ...
- win10 激活工具 Re-LoaderByR@1n.exe
名字叫 Re-LoaderByR@1n.exe 无广告, https://pan.baidu.com/s/1MBix1cZxKpUTA6MUgL7uLQ 如果变成教育版,可以用以下激活码变成专业版:W ...
- MySql新增表的字段,删除表字段
1增加两个字段: create table id_name(id int,name varchar(20));//创建原始数据表 alter table id_name add age int,add ...
- Jenkins的详细安装及使用--windows
操作环境:Windows 一.环境准备 1 安装JDK 本文采用jdk-8u111-windows-x64.exe: 2 配置tomcat 本文采用tomcat8,无需安装,配置JAVA_HOME及J ...
- 配置 Docker 加速器:适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1
天下容器, 唯快不破 Docker Hub 提供众多镜像,你可以从中自由下载数十万计的免费应用镜像, 这些镜像作为 docker 生态圈的基石,是我们使用和学习 docker 不可或缺的资源.为了解决 ...
- 页面报错时隐藏Tomcat信息
一.问题描述Tomcat报错页面泄漏Apache Tomcat/8.0.53相关版本号信息,是攻击者攻击的途径之一.因此实际当中建议去掉版本号信息. 二.解决办法1.进入到tomcat/lib目录下, ...
- node+mongoose+vue
app.js 入门 let express = require('express'); let app = express(); let allowCrossDomain = function (re ...
- js 获取两个时间戳之间相隔多少天多少小时多少分多少秒
<script> function getRemainderTime (startTime){ var s1 = new Date(startTime.replace(/-/g, &quo ...
- vuejs使用jsx语法
想要vuejs项目支持jsx语法,需要一些插件 babel-plugin-transform-vue-jsx Babel plugin for Vue 2.0 JSX 使用方法: 安装 npm ins ...