๐ป Coding Problems Solving/Stack | Queue
[LeetCode] FindKPairsWithSmallestSums
1. ๋ฌธ์ : https://leetcode.com/problems/find-k-pairs-with-smallest-sums/description/ 2. ํ์ด pq์ ๋ฃ๋ ๋ฐฉ์์ ์ ์๊ฐํ์ด์ผํ๋ค. 3. ์ฝ๋ class Solution { public List kSmallestPairs(int[] nums1, int[] nums2, int k) { List result = new ArrayList(); Queue queue = new PriorityQueue((a, b) -> (a[0] + a[1] - b[0] - b[1])); for (int idx = 0; idx < nums1.length && idx < k; idx++) { queue.offer(new int[] { nums1[idx], nums2..
2023. 7. 17. 21:09
์ต๊ทผ๋๊ธ