242. Valid Anagram*
来源:互联网 发布:android 服务器 阿里云 编辑:程序博客网 时间:2024/09/21 09:02
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.
My code:
class Solution(object): def isAnagram(self, s, t): """ :type s: str :type t: str :rtype: bool """ if len(s)!= len(t) or s== None or t == None: return False cmpDict = {} for i in range(len(s)): if s[i] in cmpDict: cmpDict[s[i]] += 1 else: cmpDict[s[i]] = 1 if t[i] in cmpDict: cmpDict[t[i]] -= 1 else: cmpDict[t[i]] = -1 for key in cmpDict.keys(): if cmpDict[key]!=0: return False return True
0 0
- [leetcode] 242.Valid Anagram
- 242.Valid Anagram
- leetcode 242. Valid Anagram
- 242. Valid Anagram
- [leetcode] 242. Valid Anagram
- leetCode 242. Valid Anagram
- Leetcode 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram LeetCode
- 242. Valid Anagram
- LeetCode 242. Valid Anagram
- LeetCode 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 242. Valid Anagram
- 数学题目
- Axis2用法——soap消息携带消息头
- 求二叉树的深度
- linux下其他分区无法挂载的问题修复
- 致雅嵌入式工作室——为Wi-Fi小车增加功能
- 242. Valid Anagram*
- Java设计模式---代理模式(二)---动态代理
- Codeforces Round #367 (Div. 2)A
- 滑动到底部点击返回,滑动返回到顶部
- mysql 将null转为0
- spring代理-01
- 链表
- 最大价值(DP)
- C++中引用的研究