File tree Expand file tree Collapse file tree 1 file changed +1
-2
lines changed Expand file tree Collapse file tree 1 file changed +1
-2
lines changed Original file line number Diff line number Diff line change 5
5
// [ํ์ด]
6
6
// 1. <์ซ์: ๋น๋์>๋ฅผ ์ ์ฅํ๋ HashMap๊ณผ [๋น๋์, ์ซ์]๋ฅผ ์ ์ฅํ๋ PriorityQueue๋ฅผ ์ ์ธํ๋ค.
7
7
// 2. HashMap์ ์ซ์๋ณ๋ก ๋น๋์๋ฅผ ํจ๊ป ์ ์ฅํด์ ํด์ํ
์ด๋ธ์ ๋ง๋ ๋ค.
8
- // 3.
9
8
// [์ฐ์ ์์ ํ์ ์ฌ์ฉ๋ ์๋ฃ๊ตฌ์กฐ]
10
9
// 1. ๋ณ๋ ํด๋์ค๋ฅผ ์ ์ธ
11
10
// 2. ์๊ตฌ์ฌํญ ์๋ฃํ ๋ฐฐ์ด์ ์ ์ธํ๋ค.
15
14
// 1. ์ฐ์ ์์ ํ๋ ๋งค๋ฒ ์์๊ฐ ์ถ๊ฐ๋ ๋๋ง๋ค ๋ด๋ถ ์ ๋ ฌ์ ์ํํ๊ธฐ ๋๋ฌธ์ ์ฐ์ฐ์ ์ํํ๋ฉด์ k๊ฐ๋ฅผ ์ ์งํด์ผ ํ๋ค.
16
15
// ๋ํ ๊ธฐ์กด [๋น๋์, ์ซ์]๋ฅผ ๋ฒ๋ ค์ผ๋ง ์ฌ๋ฐ๋ฅธ ๋ต์ ๋์ถํ ์ ์์๋ค.
17
16
// 2. [์ซ์, ๋น๋์]๋ก ์ ์ฅํ๋ ๊ฒ๋ง ์๊ฐํ๋๋ ๋ด๋ถ ์ ๋ ฌ์ ์ด๋ป๊ฒ ํ์ง ๋ชปํด์ ๊ต์ฅํ ๊ณ ๋ฏผํ๋ค. ์ ๋ต์ ๋ฐ๋์๋ค.
18
- //
17
+
19
18
class Solution {
20
19
public int [] topKFrequent (int [] nums , int k ) {
21
20
int [] answer = new int [k ];
You canโt perform that action at this time.
0 commit comments