[코테] 리트코드 정렬 242. Valid Anagram
242. Valid Anagram
문제 링크
https://leetcode.com/problems/valid-anagram/description/
문제 설명
Given 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.
제한 사항
- 1 <= s.length, t.length <= 5 * 10^4
- s and t consist of lowercase English letters.
입출력 예 #1
- Input : s = “anagram”, t = “nagaram”
- Output : true
입출력 예 #2
- Input : s = “rat”, t = “car”
- Output : false
문제 풀이
두 문자열을 정렬한 결과가 동일한 지 출력하면 된다.
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
return sorted(s) == sorted(t)
Comments