반응형
Notice
Recent Posts
Recent Comments
- Today
- Total
작심삼일
[LeetCode] 242 | Valid Anagram | Python 본문
728x90
반응형
문제 링크: https://leetcode.com/problems/valid-anagram/
문제
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.
내 풀이
s의 순서를 바꿔서 t로 만들 수 있다면, s를 알파벳 순으로 정렬한 것과 t를 알파벳 순으로 정렬한 것이 같아야 한다.
코드
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
return sorted(s) == sorted(t)
728x90
반응형
'스터디 > 코테' 카테고리의 다른 글
[LeetCode] 62 | Unique Paths | Python (0) | 2022.08.01 |
---|---|
[LeetCode] 890 | Find and Replace Pattern | Python (0) | 2022.07.29 |
[LeetCode] 114 | Flatten Binary Tree to Linked List | Python (0) | 2022.07.27 |
[LeetCode] 236 | Lowest Common Ancestor of a Binary Tree | Python (0) | 2022.07.26 |
[LeetCode] 34 | Find First and Last Position of Element in Sorted Array | Python (0) | 2022.07.25 |
Comments