diff --git a/JungHwan/NeetCode_AnagramGroups.py b/JungHwan/NeetCode_AnagramGroups.py new file mode 100644 index 0000000..9ca4d51 --- /dev/null +++ b/JungHwan/NeetCode_AnagramGroups.py @@ -0,0 +1,22 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + if(len(s) != len(t)): return False + for i in s: + if(s.count(i) != t.count(i)): + return False + return True + + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + answers = [] + while(len(strs) != 0): + print(strs) + s = strs.pop(0) + answer = [s] + newList = strs[:] + for i in strs: + if Solution.isAnagram(Solution, s, i): + answer.append(i) + newList.remove(i) + strs = newList + answers.append(answer) + return answers \ No newline at end of file