LeetCode 1755. Closest Subsequence Sum
Brute Force + Binary Search + Meet in the Middle
Input: nums = [5,-7,3,5], goal = 6
Output: 0
Explanation: Choose the whole array as a subsequence, with a sum of 6.
This is equal to the goal, so the absolute difference is 0.Input: nums = [7,-9,15,-2], goal = -5
Output: 1
Explanation: Choose the subsequence [7,-9,-2], with a sum of -4.
The absolute difference is abs(-4 - (-5)) = abs(1) = 1, which is the minimum.Input: nums = [1,2,3], goal = -7
Output: 7Solution:
PreviousLeetCode 1754. Largest Merge Of Two StringsNextLeetCode 1760. Minimum Limit of Balls in a Bag
Last updated