Given an array ofnpositive integers and a positive integers, find the minimal length of a subarray of which the sum ≥s. If there isn't one, return 0 i...
分类:
其他好文 时间:
2015-05-18 10:26:08
阅读次数:
266
动态规划解决方法:动态规划基本思想(当前N的值由N-1的值推出)class Solution {public:int maxSubArray(int A[], int n) {int res=A[0];int sum=A[0];for(int i=1;i{sum=max(sum+A[i],A[i])...
分类:
其他好文 时间:
2015-05-17 16:30:21
阅读次数:
131
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return
0 instead.
For example, given the array [2,3...
分类:
其他好文 时间:
2015-05-16 09:13:30
阅读次数:
107
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [?2,1,?3,4,?1,2,...
分类:
编程语言 时间:
2015-05-15 10:35:46
阅读次数:
160
Given an array ofnpositive integers and a positive integers, find the minimal length of a subarray of which the sum ≥s. If there isn't one, return 0 i...
分类:
其他好文 时间:
2015-05-14 18:01:36
阅读次数:
142
leetcode : Minimum Size Subarray Sum...
分类:
其他好文 时间:
2015-05-14 07:32:57
阅读次数:
115
Given an array ofnpositive integers and a positive integers, find the minimal length of a subarray of which the sum ≥s. If there isn't one, return 0 i...
分类:
其他好文 时间:
2015-05-13 18:39:21
阅读次数:
89
O(n): Sliding window:class Solution {public: int minSubArrayLen(int s, vector& nums) { int len = nums.size(); if (len == 0) return...
分类:
其他好文 时间:
2015-05-13 16:06:43
阅读次数:
123
题目
思路
O(n)的思路比较简单,直接用两个下标扫一遍即可;
O(nLogn)有点难,个人感觉应该是先得到Sum[i](前i+1)个数的和,因为数字都是正数,那么Sum数组可以用二分查找。我们扫一遍Sum,再二分查找符合条件的前一个Sum的位置即可。代码
O(n):int minSubArrayLen(int s, int * nums, int numsSize) {
int s...
分类:
其他好文 时间:
2015-05-13 07:40:25
阅读次数:
127