hashing-1 solutions#2280
Conversation
Grouping Anagrams Together (groupAnagrams.py)
Improved version without changing the algorithm: from collections import defaultdict
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
anagram_groups = defaultdict(list)
for s in strs:
key = ''.join(sorted(s))
anagram_groups[key].append(s)
return list(anagram_groups.values())This is more Pythonic. VERDICT: PASS Isomorphic Strings (isIsomorphic.py)Your solution is correct and efficient. You have correctly implemented the necessary checks to ensure that the mapping is consistent and that no two characters in
Here's a revised version of your code with these improvements: class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
if len(s) != len(t):
return False
mapping = {}
mapped_t_chars = set()
for char_s, char_t in zip(s, t):
if char_s in mapping:
if mapping[char_s] != char_t:
return False
else:
if char_t in mapped_t_chars:
return False
mapping[char_s] = char_t
mapped_t_chars.add(char_t)
return TrueOverall, your solution is good. Keep up the good work! VERDICT: PASS Word Pattern (wordPattern.py)Your solution is well-structured and follows the problem requirements correctly. Here are some strengths and areas for improvement: Strengths:
Areas for Improvement:
Overall, your solution is efficient and correct. Keep up the good work! VERDICT: PASS |
No description provided.