[LintCode] Subarray Sum & Subarray Sum II - Eason Liu - 博客园
Given an integer array, find a subarray where the sum of numbers is between two given interval. Your code should return the number of possible answer.
Example
Given [1,2,3,4]
and interval = [1,3]
, return 4
. The possible answers are:
[0, 0] [0, 1] [1, 1] [3, 3]
先求出前缀和,然后枚举求两个前缀和的差。如果差在start与end之间,就给res+1。注意前缀和数组前要插入一个0。
Read full article from [LintCode] Subarray Sum & Subarray Sum II - Eason Liu - 博客园
No comments:
Post a Comment