Skip to content

Commit d76d1e6

Browse files
edit 347
1 parent 9a6feb6 commit d76d1e6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ Your ideas/fixes/algorithms are more than welcome!
232232
|350|[Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/IntersectionOfTwoArraysII.java)| O(m+n)|O((m+n)) could be optimized | Easy| HashMap, Binary Search
233233
|349|[Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/)|[Solution](../master/src/main/java/com/fishercoder/solutions/IntersectionOfTwoArrays.java)| O(m+n)|O(min(m,n)) | Easy| Two Pointers, Binary Search
234234
|348|[Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_348.java)| O(1)|O(n) | Medium| Design
235+
|347|[Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_347.java)| O(n)|O(1) | Medium| HashTable, Heap
235236
|346|[Moving Average from Data Stream](https://leetcode.com/problems/moving-average-from-data-stream/)|[Solution](../master/src/main/java/com/fishercoder/solutions/MovingAveragefromDataStream.java)| O(1)|O(w)) | Easy| Queue
236237
|344|[Reverse String](https://leetcode.com/problems/reverse-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/ReverseString.java) | O(n) |O(1) | Easy | String
237238
|343|[Integer Break](https://leetcode.com/problems/integer-break/)|[Solution](../master/src/main/java/com/fishercoder/solutions/IntegerBreak.java)| O(1)|O(1) | Medium| Math

src/main/java/com/fishercoder/solutions/TopKFrequentElements.java renamed to src/main/java/com/fishercoder/solutions/_347.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99
import java.util.PriorityQueue;
1010
import java.util.Queue;
1111

12-
/**Given a non-empty array of integers, return the k most frequent elements.
12+
/**
13+
* 347. Top K Frequent Elements
14+
*
15+
* Given a non-empty array of integers, return the k most frequent elements.
1316
1417
For example,
1518
Given [1,1,1,2,2,3] and k = 2, return [1,2].
1619
1720
Note:
1821
You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
1922
Your algorithm's time complexity must be better than O(n log n), where n is the array's size.*/
20-
public class TopKFrequentElements {
23+
24+
public class _347 {
2125
// Approach 1: use buckets to hold numbers of the same frequency
2226
/**Attn: we must use a simple array to solve this problem, instead of using List<List<Integer>>,
2327
* we have to use List<Integer>[], otherwise, cases like this one: [-1,-1]
@@ -98,7 +102,7 @@ else if (o1.getValue() < o2.getValue())
98102

99103
public static void main(String[] args) {
100104
int[] nums = new int[] { 3, 0, 1, 0 };
101-
TopKFrequentElements test = new TopKFrequentElements();
105+
_347 test = new _347();
102106
test.topKFrequent_using_heap(nums, 1);
103107
// test.topKFrequent_using_bucket(nums, 1);
104108
}

0 commit comments

Comments
 (0)