Leetcode - K SUM Problem
373. Find K Pairs with Smallest Sums[M]
https://leetcode.com/problems/find-k-pairs-with-smallest-sums/
Description
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.
Define a pair (u,v) which consists of one element from the first array and one element from the second array.
Find the k pairs (u1,v1),(u2,v2) …(uk,vk) with the smallest sums.
Example 1:
1 | Input: nums1 = [1,7,11], nums2 = [2,4,6], k = 3 |
Example 2:
1 | Input: nums1 = [1,1,2], nums2 = [1,2,3], k = 2 |
Example 3:
1 | Input: nums1 = [1,2], nums2 = [3], k = 3 |
Solution
https://discuss.leetcode.com/topic/50450/slow-1-liner-to-fast-solutions
1 |
416. Partition Equal Subset Sum[M]
https://leetcode.com/problems/partition-equal-subset-sum/
Description
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
Note:
- Each of the array element will not exceed 100.
- The array size will not exceed 200.
Example 1:
1 | Input: [1, 5, 11, 5] |
Example 2:
1 | Input: [1, 2, 3, 5] |
Solution
1 | class Solution: |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment





