LeetCode 솔루션 분류
[7/28] 242. Valid Anagram
작성자 정보
- 학부유학생 작성
- 작성일
본문
Easy
5889232Add to ListShareGiven two strings s
and t
, return true
if t
is an anagram of s
, and false
otherwise.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Example 1:
Input: s = "anagram", t = "nagaram" Output: true
Example 2:
Input: s = "rat", t = "car" Output: false
Constraints:
1 <= s.length, t.length <= 5 * 104
s
andt
consist of lowercase English letters.
Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?
Accepted
1,473,092
Submissions
2,373,483
관련자료
-
링크
댓글 1
학부유학생님의 댓글
- 학부유학생
- 작성일
Runtime: 73 ms, faster than 56.26% of Python3 online submissions for Valid Anagram.
Memory Usage: 14.4 MB, less than 96.92% of Python3 online submissions for Valid Anagram.
Memory Usage: 14.4 MB, less than 96.92% of Python3 online submissions for Valid Anagram.
import collections
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
return collections.Counter(s) == collections.Counter(t)