Skip to content

Commit b9723d9

Browse files
committed
fd
1 parent 7af9a0b commit b9723d9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

solution/src/main/java/com/inuker/solution/TopKFrequentElements.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public int compare(Integer o1, Integer o2) {
4444
}
4545

4646
// 耗时23ms,时间复杂度O(n),空间复杂度O(n)
47+
// 这里有个问题,result的size可能大于k了
4748
public List<Integer> topKFrequent2(int[] nums, int k) {
4849
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
4950
int max = 0;
@@ -66,6 +67,6 @@ public List<Integer> topKFrequent2(int[] nums, int k) {
6667
result.addAll(lists[i]);
6768
}
6869
}
69-
return result;
70+
return result.subList(0, k);
7071
}
7172
}

0 commit comments

Comments
 (0)