Skip to content

Commit 487db4c

Browse files
committed
refactor: optimize result slice initialization in topKFrequent function
1 parent 872f333 commit 487db4c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

top-k-frequent-elements/neverlish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func topKFrequent(nums []int, k int) []int {
2626
freq_by_counts[count] = append(freq_by_counts[count], num)
2727
}
2828

29-
result := []int{}
29+
result := make([]int, 0, k)
3030

3131
for count := len(nums); count > 0; count-- {
3232
if nums, ok := freq_by_counts[count]; ok {

0 commit comments

Comments
 (0)