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: 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.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
题目大意: 给你两个字符串,判断是否成字谜。成字谜的意思就是元素可能顺序错乱,判断字符串的所有元素是否相同。
把字符串分别存到两个集合中,然后对集合进行排序,再比较。
提示,如果遇到Unicode字符怎么办?
上代码
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
list_s = []
list_t = []
for i in s:
list_s.append(i)
for j in t:
list_t.append(j)
return sorted(list_s) == sorted(list_t)
排序遇到Unicode也没关系,一样的排序规则。
疫情中的英国,
据说下周就解禁了,
加油!
19/05/2020