Leetcode学习(40)—— Valid Anagram
来源:互联网 发布:西门子ug软件侵权 编辑:程序博客网 时间:2024/06/11 05:00
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): dic1 = dic2 = {} for i in s: dic1[i] = dic1.get(i, 0) + 1 for j in t: dic2[j] = dic2.get(j, 0) + 1 return dic1 == dic2'''class Solution(object): def isAnagram(self, s, t): return sorted(s) == sorted(t)'''
字典求解:
时间复杂度为 O(n)
排序求解:
时间复杂度为 O(nlogn)
0 0
- Leetcode学习(40)—— Valid Anagram
- LeetCode(七)——Valid Anagram
- Leetcode——242. Valid Anagram
- LeetCode(242)Valid Anagram
- leetcode解题报告242——Valid Anagram
- leetcode刷题日记——Valid Anagram
- <LeetCode><Easy>242Valid Anagram (排序)
- Leetcode:242. Valid Anagram(JAVA)
- LeetCode之旅(13)-Valid Anagram
- LeetCode:有效变形词(Valid Anagram)
- leetcode(5),Valid Anagram(python)
- LeetCode 242. Valid Anagram 题解(C++)
- Leetcode #242 Valid Anagram
- leetcode-242-Valid Anagram
- Leetcode: Valid Anagram
- 【leetCode】Valid Anagram
- [leetcode] 242.Valid Anagram
- leetcode 242: Valid Anagram
- 百万级数据查询优化之in
- 杭电2209 翻纸牌游戏 DFS BFS 搜索
- cocos-js,数据本地存储
- BCP 数据的导入和导出
- Python学习随机(第二弹)
- Leetcode学习(40)—— Valid Anagram
- 使用Ado.net执行SP很慢,而用SSMS执行很快
- CODEVS 4511 信息传递
- mac 下载编译Android源码
- JDK中的URLConnection参数详解
- 分布式架构学习之:006--构建Dubbo服务消费者Web应用的war包并在Tomcat中部署
- phoenix使用
- iOS添加启动页图片添加设置
- SSIS 数据流优化