This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // O(n) | |
| func topKFrequent(nums []int, k int) []int { | |
| if len(nums) < k { | |
| return nums | |
| } | |
| frequency := make(map[int]int) | |
| sortedBucket := make([][]int, len(nums)+1) | |
| for _, v := range nums { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // O(m*n*26)-> O(m*n) | |
| func groupAnagrams(strs []string) [][]string { | |
| anagramMap := make(map[string][]string) | |
| // n | |
| for _, str := range strs { | |
| keyCount := make([]int, 26) | |
| // length of average string, m | |
| for _, r := range str { |