Given two strings s and , write a function to determine if t is an anagram of s.

Example 1:

Input: s = "anagram", t = "nagaram"
Output: true

Example 2:

Input: s = "rat", t = "car"
Output: false

Note:
You may assume the string contains only lowercase alphabets.

from collections import Counter
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
if len(s)!=len(t):
return False
s1=Counter(s)
t1=Counter(t) for i in s1:
if s1[i]!=t1[i]:
return False
return True

  

[LeetCode&Python] Problem 242. Valid Anagram的更多相关文章

  1. 【leetcode❤python】242. Valid Anagram

    class Solution(object):    def isAnagram(self, s, t):        if sorted(list(s.lower()))==sorted(list ...

  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. 242. Valid Anagram(C++)

    242. Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. ...

  5. 【LeetCode】242. Valid Anagram (2 solutions)

    Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For ...

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

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

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

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

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

随机推荐

  1. 使用JQuery 合并两个 json 对象

    一,保存object1和2合并后产生新对象,若2中有与1相同的key,默认2将会覆盖1的值 var object = $.extend({}, object1, object2); 二,将2的值合并到 ...

  2. 微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题

    几天不动代码,再运行成这样了, {errMsg: "getLocation:fail Error: tunneling socket could not…d, cause=connect E ...

  3. vue-cli webpack全局引入jquery

    1.首先在package.json里加入, dependencies:{ "jquery" : "^2.2.3" } 2.安装依赖 npm install jq ...

  4. idea中deBug方法

    1 2设置controller层断点鼠标左键点击,断点在哪里,就会deBug到哪里 3刷新页面 4查看 5service层设置断点 6 7查看返回信息是否错误

  5. MySQL(一) 初识MySQL

    数据库基础 数据库是由一批数据构成的有序的集合,这些数据被存放在结构化的数据表里.数据表之间相互联系,反映了客观事物间的本质联系.数据库系统提供对数据的安全控制和完整性控制. 什么是数据库 数据库的发 ...

  6. POJ 2456 Agressive cows(二分)

    POJ 2456 Agressive cows 农夫 John 建造了一座很长的畜栏,它包括N (2≤N≤100,000)个隔间,这 些小隔间的位置为x0,...,xN-1 (0≤xi≤1,000,0 ...

  7. EtherCAT(扒自百度百科)

    EtherCAT(以太网控制自动化技术)是一个开放架构,以以太网为基础的现场总线系统,其名称的CAT为控制自动化技术(Control Automation Technology)字首的缩写.Ether ...

  8. day25-python操作redis一

    1.     Python操作nosql数据库 NoSQL,泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应付web2.0网站,特别是超大规模和高并发的SNS类型的web2 ...

  9. python中list方法总结

    stu=[s1,s2,s3,s4,s5] #list列表/数组 列表的下标/索引是从0开始的: 定义一个列表:XX=[,,,,,] 定义一个空列表:XX=[] or XX=list() #增加一个元素 ...

  10. [leetcode121]股票买卖 Best Time to Buy and Sell Kadane算法

    [题目] Say you have an array for which the ith element is the price of a given stock on day i. If you ...