leetcode 242. Valid Anagram
来源:互联网 发布:河北工龄工资算法 编辑:程序博客网 时间:2024/06/14 13:23
Python leetcode
242. Valid Anagram
242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
猜谜语,就是判断一个字符串的的所有元素和另一个字符串所有元素一样,只是顺序不一样而已
#coding=utf-8
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
#ss = sorted(list(s))
ss = sorted(s)
print ss
#tt = sorted(list(t))
tt = sorted(t)
print tt
return ss==tt
def isAnagram1(self,s,t):
sdict={};tdict={}
for item in s:
sdict[item]=sdict.get(item,0)+1
for item in t:
tdict[item]=tdict.get(item,0)+1
return sdict==tdict
S=Solution()
s='anagram';t='nagaram'
print S.isAnagram1(s,t)
0 0
- [leetcode] 242.Valid Anagram
- leetcode 242. Valid Anagram
- [leetcode] 242. Valid Anagram
- leetCode 242. Valid Anagram
- Leetcode 242. Valid Anagram
- 242. Valid Anagram LeetCode
- LeetCode 242. Valid Anagram
- LeetCode 242. Valid Anagram
- [LeetCode]242. Valid Anagram
- 【LeetCode】242. Valid Anagram
- leetcode 242. Valid Anagram
- leetcode 242. Valid Anagram
- LeetCode--242. Valid Anagram
- LeetCode *** 242. Valid Anagram
- #leetcode#242. Valid Anagram
- leetcode 242. Valid Anagram
- LeetCode 242. Valid Anagram
- 242.[LeetCode]Valid Anagram
- new Integer()和Integer.valueOf()效率比较
- 二叉树非递归遍历之层次遍历,先序、中序遍历
- Android 银行转账(事务)
- 文章标题
- 0416 css列表
- leetcode 242. Valid Anagram
- C++ 牛客网做题笔记【700题总结】
- Charactor controller
- 实现带复选框的下拉列表
- 0416 css超链接
- win10 默认程序 edge
- 0416 盒子模型
- Java Socket编程与客户/服务器应用开发(三)
- LeetCode 521. Longest Uncommon Subsequence I