Practice/Meta/Leetcode 377. Combination Sum IV
CodingOptional
Given an array of distinct positive integers nums and a target integer target, return the total count of different ordered sequences that sum exactly to target. You may use each number from nums as many times as needed.
Important: The order of numbers in a sequence matters. For example, [1, 2] and [2, 1] are considered two different sequences.
targetnums can be reused unlimited timesnums are distinct and positivenums are uniqueExample 1:
Input: nums = [1, 2, 3], target = 4 Output: 7 Explanation: The possible sequences are: [1, 1, 1, 1] [1, 1, 2] [1, 2, 1] [2, 1, 1] [2, 2] [1, 3] [3, 1]
Example 2:
Input: nums = [9], target = 3 Output: 0 Explanation: There is no way to sum to 3 using only the number 9
Example 3:
Input: nums = [1, 2, 5], target = 5 Output: 9 Explanation: The possible sequences include: [1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 2, 1], [1, 2, 1, 1], [2, 1, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1], [5]