LintCode "Subarray Sum II"】的更多相关文章

Sliding window doesn't work. So it is a typical partial_sum base solution. As below. However if you use a balanced binary search tree, you can get O(nlgn) - like std::set<int> class Solution { public: /** * @param A an integer array * @param start a…
Subarray Sum Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the last number. Example Given [-3, 1, 2, -3, 4], return [0, 2] or [1, 3]. 用hashmap来存从nums[0…
Continuous Subarray Sum II   Given an circular integer array (the next element of the last element is the first element), find a continuous subarray in it, where the sum of numbers is the biggest. Your code should return the index of the first number…
Given an integer array, find a continuous rotate subarray where the sum of numbers is the biggest. Your code should return the index of the first number and the index of the last number. (If their are duplicate answer, return anyone. The answer can b…
Subarray Sum 原题链接:http://lintcode.com/zh-cn/problem/subarray-sum/# Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the last number. 样例 Given [-3, 1, 2, -…
Given n unique integers, number k (1<=k<=n) and target. Find all possible k integers where their sum is target. Example Given [1,2,3,4], k=2, target=5, [1,4] and [2,3] are possible solutions. 这道题同Combination Sum II public class Solution { /** * @par…
Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number. Have you met this question in a real interview? Yes Example Given [-3, 1, 1, -3, 5], return [0, 2], [1, 3], [1, 1], [2, 2] or [0…
Description Given an positive integer array A and an interval. Return the number of subarrays whose sum is in the range of given interval. Subarray is a part of origin array with continuous index. Example Example 1: Input: A = [1, 2, 3, 4], start = 1…
Description Given an circular integer array (the next element of the last element is the first element), find a continuous subarray in it, where the sum of numbers is the biggest. Your code should return the index of the first number and the index of…
For this problem we need to learn a new trick that if your start sum up all elements in an array. When you start from a to b to sum up all elements, if the result is zero, and also the summation of all elements from index a to c ( c<=b ) is zero. The…