← 返回 amazon 的题目列表Longest Subarray with Target Sum
类型:online_judge
Given an integer array and a target value, find the longest continuous subarray that sums up to the target value. If no such subarray exists, return 0. The time complexity should be O(n).
Input
An integer array nums of length n
An integer target
Output
An integer representing the length of the longest subarray
Example
Input: nums = [1, -1, 5, -2, 3], target = 3 Output: 4
Input: nums = [-2, -1, 2, 1], target = 1 Output: 2
Constraints
The total number of elements in nums, n, is a positive integer
-10^9 ≤ nums[i] ≤ 10^9
-10^9 ≤ target ≤ 10^9
Example
Input
1 -1 5 -2 3
3