← 返回 bytedance 的题目列表Subarray with Given Sum
类型:online_judge
Given an integer array and a target integer k, find the shortest contiguous subarray whose sum equals k. Return the length of that subarray. If such subarray does not exist, return 0.
Input:
An integer array nums.
Target integer k.
Output: The length of the shortest subarray that sums up to k.
Example:
Input: nums = [2,3,1,2,4,3], k = 7
Output: 2
Explanation: Because [4,3] is the shortest subarray that sums up to 7.
Constraints:
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^4
Example
Input
2 3 1 2 4 3
7