Equivalent Transformation¶
Table of Contents¶
- 3375. Minimum Operations to Make Array Values Equal to K (Easy)
- 2914. Minimum Number of Changes to Make Binary String Beautiful (Medium)
- 3365. Rearrange K Substrings to Form Target String (Medium)
- 1657. Determine if Two Strings Are Close (Medium)
- 2551. Put Marbles in Bags (Hard)
- 1585. Check If String Is Transformable With Substring Sort Operations (Hard)
- 1040. Moving Stones Until Consecutive II (Medium)
- 249. Group Shifted Strings (Medium) 👑
- 49. Group Anagrams (Medium)
- 1183. Maximum Number of Ones (Hard) 👑
3375. Minimum Operations to Make Array Values Equal to K¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: array, hash table
2914. Minimum Number of Changes to Make Binary String Beautiful¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: string
3365. Rearrange K Substrings to Form Target String¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: hash table, string, sorting
1657. Determine if Two Strings Are Close¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: hash table, string, sorting, counting
2551. Put Marbles in Bags¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, greedy, sorting, heap priority queue
1585. Check If String Is Transformable With Substring Sort Operations¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: string, greedy, sorting
1040. Moving Stones Until Consecutive II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, two pointers, sorting
249. Group Shifted Strings¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, hash table, string
49. Group Anagrams¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, hash table, string, sorting
49. Group Anagrams - Python Solution
from collections import defaultdict
from typing import List
# Hash - List
def groupAnagrams(strs: List[str]) -> List[List[str]]:
result = defaultdict(list)
for s in strs:
count = [0] * 26
for i in s:
count[ord(i) - ord("a")] += 1
result[tuple(count)].append(s)
return list(result.values())
# |-------------|-----------------|--------------|
# | Approach | Time | Space |
# |-------------|-----------------|--------------|
# | Hash | O(n * k) | O(n) |
# |-------------|-----------------|--------------|
strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
print(groupAnagrams(strs))
# [['eat', 'tea', 'ate'], ['tan', 'nat'], ['bat']]
1183. Maximum Number of Ones¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, greedy, sorting, heap priority queue