25/12/2024, 17:39 My Solutions to Blind 75 - LeetCode Discuss
Explore Problems Contest Discuss Interview Store 0
#Transpose
n = len(matrix)
for i in range(n):
for j in range(i):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
#Swap columns
for i in range(n):
matrix[i] = matrix[i][::-1]
//Go
func reverse(array []int) []int {
m := len(array)
for i := 0; i < m/2; i++ {
array[i], array[m-i-1] = array[m-i-1], array[i]
}
return array
}
func rotate(matrix [][]int) {
n := len(matrix)
for i := 0; i < n; i++ {
for j := 0; j < i; j++ {
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
}
}
for i := 0; i < n; i++ {
matrix[i] = reverse(matrix[i])
}
Group Anagrams
Time Complexity: O(n ⋅ k log k) -|- k = length of longest anagram
Space Complexity: O(n)
#Python3
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
mapper = {}
for string in strs:
sorted_str = str(sorted(string))
if sorted_str in mapper:
mapper[sorted_str].append(string)
else:
mapper[sorted_str] = [string]
return list(mapper.values())
golang python3 go blind 75 grind 75
Comments: 0 Best Most Votes Newest to Oldest Oldest to New
https://leetcode.com/discuss/interview-question/4915703/my-solutions-to-blind-75 1/1