[leetCode刷题笔记]373. Find K Pairs with Smallest Sums
来源:互联网 发布:windows图形编程原理 编辑:程序博客网 时间:2024/06/10 02:28
public class Solution { public List<int[]> kSmallestPairs(int[] nums1, int[] nums2, int k) { PriorityQueue<int[]> queue = new PriorityQueue<>((a,b)->a[0]+a[1]-b[0]-b[1]); List<int[]> res = new ArrayList<>(); if(nums1.length==0 || nums2.length==0 || k==0) return res; for(int i = 0; i < nums1.length && i < k; i++) queue.offer(new int[]{nums1[i], nums2[0], 0}); while (k-- > 0 && !queue.isEmpty()) { int[] cur = queue.poll(); res.add(new int[]{cur[0], cur[1]}); if(cur[2] == nums2.length - 1) continue; queue.offer(new int[]{cur[0] ,nums2[cur[2] + 1], cur[2] + 1}); } return res; }}
阅读全文
0 0
- [leetCode刷题笔记]373. Find K Pairs with Smallest Sums
- 【Leetcode】Find K Pairs with Smallest Sums
- leetcode Find K Pairs with Smallest Sums
- leetcode Find K Pairs with Smallest Sums
- LeetCode: Find K Pairs with Smallest Sums
- Leetcode: Find K Pairs with Smallest Sums
- leetcode-Find K Pairs with Smallest Sums
- leetcode 373. Find K Pairs with Smallest Sums
- LeetCode—373. Find K Pairs with Smallest Sums
- [leetcode] 373. Find K Pairs with Smallest Sums
- [leetcode] 373. Find K Pairs with Smallest Sums 解题报告
- leetcode.373. Find K Pairs with Smallest Sums
- LeetCode 373. Find K Pairs with Smallest Sums
- Leetcode 373. Find K Pairs with Smallest Sums(Python)
- [leetcode]373. Find K Pairs with Smallest Sums -- JavaScript代码
- [leetcode] 373. Find K Pairs with Smallest Sums
- leetcode 373. Find K Pairs with Smallest Sums
- Leetcode 373. Find K Pairs with Smallest Sums
- Nginx 配置简述
- 第一章:控制结构和函数
- VC++与java进行socket通讯
- "1+2+3+4+...+100" = 5050
- linux mint 终端命令安装最新wine
- [leetCode刷题笔记]373. Find K Pairs with Smallest Sums
- 【zabbix教程七】——zabbix3.0配置微信报警
- 数字计算格式问题
- 【zabbix教程九】——zabbix3.0 批量添加端口监控
- 多年iOS开发经验总结(一)
- axis调用webservice服务
- 从日期转换为字符串
- 面试题32. 从1到n整数中 1出现的次数
- 修改Write.exe实现运行框中输入中文打开相应程序