Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 7. 28. 23:45
https://leetcode.com/problems/valid-anagram/
Valid Anagram - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
dictionary 개념으로 푼 문제. 역시 Easy는 풀만해..
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
l = len(s)
if l != len(t):
return False
ar = [0 for _ in range(26)]
for i in range(l):
ar[ord(s[i])-ord('a')] += 1
ar[ord(t[i])-ord('a')] -= 1
for i in range(26):
if ar[i]:
return False
return True
반응형