algorithm-dryad's People
Forkers
jinyuwang ykppingfan dkui97 gemvinci jichuncheng maochengfag deanwang2018 wenxuejiang610 joeylin311 wanggr closess zhangjing9898 pendicool realm2go jerryzcs songwenju reds123 zhengxinbao christmasferret henry-diasa yylgit xhwutao zzshi97 scyslz leikei happytigger ljh9999 vagueray yungthuis momokow j0ven miraclewh acoser98 houchangok orangewangjie gaoshuaidage yanshizhao dogsong99 hzy1914 goeasya xiangyouo filenotfoundexcetion liangliangdai liu-lihao whatwaterdandan wueryuan d-dragon0318 murphys-uestc cyk111 xiaocuizi pzytydy wanyinsheng zhzhsun roerfly blankkelly fuanvl fml077 kaysonyang wxyjwxyj radiancebobo icoding168 qinting513 xiaohuajun github653224 magicyork 1lo0 huangyong2002algorithm-dryad's Issues
文件没内容
在https://github.com/lagoueduCol/Algorithm-Dryad/blob/main/03.HeapAndPriorityQueue/347.%E5%89%8D-k-%E4%B8%AA%E9%AB%98%E9%A2%91%E5%85%83%E7%B4%A0.java中
代码不符合题目要求
测试数据:{3,3,4,1,1,1,2,2,3,5,5,5} 输出[1,5] 而不是[1,3]
在hashmap遍历添加时的顺序:
Node{val=1, cnt=3}
Node{val=2, cnt=2}
Node{val=3, cnt=3}
Node{val=4, cnt=1}
Node{val=5, cnt=3}
你可以用大堆,直接取出前k个top数;
int[] ans = new int[k];
int j = 0;
Queue nodes = new PriorityQueue<>((n1, n2) -> n2.cnt - n1.cnt);//小堆 比较的是次数
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
Node node =new Node(entry.getKey(), entry.getValue());
// System.out.println(node);
nodes.offer(node);
if (nodes.size() > k&&j<k) {
ans[j++] = nodes.poll().val;
}
}
https://github.com/lagoueduCol/Algorithm-Dryad/blob/main/03.HeapAndPriorityQueue/347.%E5%89%8D-k-%E4%B8%AA%E9%AB%98%E9%A2%91%E5%85%83%E7%B4%A0.java
判断queue.size() > k ,这里为啥用while循环啊,不应该用if就行了吗
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.