E-COM-NET
首页
在线工具
Layui镜像站
SUI文档
联系我们
推荐频道
Java
PHP
C++
C
C#
Python
Ruby
go语言
Scala
Servlet
Vue
MySQL
NoSQL
Redis
CSS
Oracle
SQL Server
DB2
HBase
Http
HTML5
Spring
Ajax
Jquery
JavaScript
Json
XML
NodeJs
mybatis
Hibernate
算法
设计模式
shell
数据结构
大数据
JS
消息中间件
正则表达式
Tomcat
SQL
Nginx
Shiro
Maven
Linux
Subarray
Lintcode139
Subarray
Sum Closest solution 题解
【题目描述】Givenanintegerarray,findasubarraywithsumclosesttozero.Returntheindexesofthefirstnumberandlastnumber.给定一个整数数组,找到一个和最接近于零的子数组。返回第一个和最有一个指数。你的代码应该返回满足要求的子数组的起始位置和结束位置.【题目链接】www.lintcode.com/en/prob
AdmondGuo
·
2018-01-01 22:30
lintcode
面试题
Lintcode138
Subarray
Sum solution 题解
【题目描述】Givenanintegerarray,findasubarraywherethesumofnumbersiszero.Yourcodeshouldreturntheindexofthefirstnumberandtheindexofthelastnumber.Notice:Thereisatleastonesubarraythatit'ssumequalstozero.给定一个整数数
AdmondGuo
·
2017-12-30 13:52
lintcode
面试题
Maximum Length of Repeated
Subarray
GiventwointegerarraysAandB,returnthemaximumlengthofansubarraythatappearsinbotharrays.题目意思是给定两个整型数组A和B,返回两个数组的公共子串的最大长度。样例输入如下:Example1:Input:A:[1,2,3,2,1]B:[3,2,1,4,7]Output:3Explanation:Therepeatedsu
DDB_CS
·
2017-12-11 07:37
Lintcode191 Maximum Product
Subarray
solution 题解
【题目链接】www.lintcode.com/en/problem/maximum-product-
subarray
/【题目解析】本题其实是Maxim
程风破浪会有时
·
2017-12-11 02:41
leetcode 643 Maximum Average
Subarray
I
原题是:Givenanarrayconsistingofnintegers,findthecontiguoussubarrayofgivenlengthkthathasthemaximumaveragevalue.Andyouneedtooutputthemaximumaveragevalue.Example1:Input:[1,12,-5,-6,50,3],k=4Output:12.75Expl
小双2510
·
2017-12-11 01:23
Continuous
Subarray
Sum 解题报告
题目:Givenalistofnon-negativenumbersandatargetintegerk,writeafunctiontocheckifthearrayhasacontinuoussubarrayofsizeatleast2thatsumsuptothemultipleofk,thatis,sumsupton*kwherenisalsoaninteger.Example1:Inpu
魔豆Magicbean
·
2017-12-09 12:45
IT公司面试习题
一维/二维
subarray
/子矩阵最大和
题目:一维数组找最大
subarray
和,O(n)。题目:二维矩阵找最大子矩阵和,O(min(m,n)^2*max(m,n))。见编程之美。题目:一维数组找最大
subarray
和,和不大于k。
ac932d3802ce
·
2017-12-06 07:28
Continuous
Subarray
Sum 560.
Subarray
Sum Equals K
下面两个题都是使用了unordered_map&nums,intk){if(kump;ump[0]=-1;for(inti=0;i=2)returntrue;}else{intn=0;while(n*k=2)returntrue;n++;}}if(ump.find(sum)==ump.end())ump[sum]=i;}returnfalse;}};网上看了个方法。sum_now%k=sum_ol
liqinzhe223
·
2017-12-05 16:18
leetcode
LeetCode-713:
Subarray
Product Less Than K (乘积小于K的子数组个数) -- medium
QuestionYouraregivenanarrayofpositiveintegersnums.Countandprintthenumberof(contiguous)subarrayswheretheproductofalltheelementsinthesubarrayislessthank.Example1:Input:nums=[10,5,2,6],k=100Output:8Expla
大树先生的博客
·
2017-11-10 10:43
LeetCode刷题
LeetCode
刷题
LeetCode-718:Maximum Length of Repeated
Subarray
(最长公共子数组) -- medium
QuestionGiventwointegerarraysAandB,returnthemaximumlengthofansubarraythatappearsinbotharrays.Example1:Input:A:[1,2,3,2,1]B:[3,2,1,4,7]Output:3Explanation:Therepeatedsubarraywithmaximumlengthis[3,2,1].
大树先生的博客
·
2017-11-09 13:27
LeetCode刷题
LeetCode
刷题
LeetCode-581:Shortest Unsorted Continuous
Subarray
(最短未排序连续子数组) -- easy
QuestionGivenanintegerarray,youneedtofindonecontinuoussubarraythatifyouonlysortthissubarrayinascendingorder,thenthewholearraywillbesortedinascendingorder,too.Youneedtofindtheshortestsuchsubarrayandout
大树先生的博客
·
2017-11-07 15:49
LeetCode
算法
Array
未排序子数组
Easy
LeetCode刷题
LeetCode
刷题
Leetcode:713.
Subarray
Product Less Than K
题目描述:题目:Youraregivenanarrayofpositiveintegersnums.Countandprintthenumberof(contiguous)subarrayswheretheproductofalltheelementsinthesubarrayislessthank.Example1:Input:nums=[10,5,2,6],k=100Output:8Expla
Genius_yyyyyyyyeah
·
2017-11-04 11:22
leetcode
Leetcode
Subarray
Sum Equals K
原题链接在这里:https://leetcode.com/problems/
subarray
-sum-equals-k/description/题目:Givenanarrayofintegersandanintegerk
Dylan_Java_NYC
·
2017-10-31 13:00
【Leetcode-Easy-53】Maximum
Subarray
【Leetcode-Easy-53】MaximumSubarray题目Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray[-2,1,-3,4,-1,2,1,-5,4],thecontiguoussubarray[4,-1,2,
LYZ0907
·
2017-10-18 14:33
Leetcode
LeetCode
Maximum
Subarray
题目Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray[-2,1,-3,4,-1,2,1,-5,4],thecontiguoussubarray[4,-1,2,1]hasthelargestsum=6Morepractice:
Al73r
·
2017-10-13 08:22
Maximum
Subarray
II(最大子数组 II)
http://www.lintcode.com/en/problem/maximum-
subarray
-ii/?
天街孤独
·
2017-10-12 19:43
Maximum
Subarray
- Easy
上周说要好好整理这道题的,因为确实花了很多时间去完成它。但是今天准备回顾的时候发现草稿纸一扔有很多细节记不起来了,看来还是要打铁趁热,现在我尽量写清楚自己的解题经过。DescriptionFindthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Example:Giventhear
并不想起昵称
·
2017-09-25 01:39
Minimum Size
Subarray
Sum 最短子数组的和 + 十分典型的移动窗口做法
Givenanarrayofnpositiveintegersandapositiveintegers,findtheminimallengthofacontiguoussubarrayofwhichthesum≥s.Ifthereisn’tone,return0instead.Forexample,giventhearray[2,3,1,2,4,3]ands=7,thesubarray[4,3]
JackZhangNJU
·
2017-09-21 10:38
leetcode
For
Java
需要好好想一下的题目
双指针问题
leetcode
For
C++
Maximum Product
Subarray
最大连乘子序列 + 很棒的动态规划DP做法
Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestproduct.Forexample,giventhearray[2,3,-2,4],thecontiguoussubarray[2,3]hasthelargestproduct=6.题意很简单,这里不就不说了,建议和leetcod
JackZhangNJU
·
2017-09-18 10:32
leetcode
For
Java
需要好好想一下的题目
DP动态规划
leetcode
For
C++
卡丹尔算法(max
subarray
problem)
问题介绍Sayyouhaveanarrayforwhichtheithelementisthepriceofagivenstockondayi.Ifyouwereonlypermittedtocompleteatmostonetransaction(ie,buyoneandselloneshareofthestock),designanalgorithmtofindthemaximumprofit
huizhang0110
·
2017-09-15 21:17
数据结构和算法
WEEK#17 Divide and Conquer_Maximum
Subarray
DescriptionoftheProblemFindthecontiguoussub-arraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray[-2,1,-3,4,-1,2,1,-5,4],thecontiguoussubarray[4,-1,2,1]hasthelar
DarkKnightRedoc
·
2017-09-11 12:43
53.Maximum
Subarray
题目介绍Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray[-2,1,-3,4,-1,2,1,-5,4],thecontiguoussubarray[4,-1,2,1]hasthelargestsum=6.代码(python)
l_b_n
·
2017-08-22 09:22
Leetcode-Maximum
Subarray
-Python
MaximumSubarray最大子串和问题:从一个数组中找出一个子串使其和最大。Descriptiontips:子串是指数组中连续的若干个元素,而子序列只要求各元素的顺序与其在数组中一致,而没有连续的要求。解题思路:自己没有想出来,直接借鉴了网上的动态规划思路,我觉得下面是一些解决的关键点:-对于array[1…n],如果array[i…j]就是满足和最大的子串,那么对于任何k(i=0,则sum
韦人人韦
·
2017-08-13 18:40
Python
leetcode
Algorithm
【LeetCode】560.
Subarray
Sum Equals K解题报告
【LeetCode】560.SubarraySumEqualsK解题报告tags:Array题目地址:https://leetcode.com/problems/
subarray
-sum-equals-k
郝春雨
·
2017-07-29 17:53
LeetCode
Lintcode44 Minimum
Subarray
solution 题解
【题目描述】Givenanarrayofintegers,findthesubarraywithsmallestsum.Returnthesumofthesubarray.Notice:Thesubarrayshouldcontainoneintegeratleast.给定一个整数数组,找到一个具有最小和的子数组。返回其最小和。注意:子数组最少包含一个数字【题目链接】http://www.lint
SingularPoint01
·
2017-07-21 08:27
算法
Maximum Average
Subarray
I
[LeetCode]643.MaximumAverageSubarrayI题目描述思路滑窗统计k个数的和,同时保留最大和,结果返回最大和/k代码#include#include#includeusingnamespacestd;classSolution{public:doublefindMaxAverage(vector&nums,intk){doublemax_sum=0,cur_sum=0;
charon____
·
2017-07-17 23:14
leetcode
LeetCode 523 Continuous
Subarray
Sum (同余)
Givenalistofnon-negativenumbersandatargetintegerk,writeafunctiontocheckifthearrayhasacontinuoussubarrayofsizeatleast2thatsumsuptothemultipleofk,thatis,sumsupton*kwherenisalsoaninteger.Example1:Input:[
_TCgogogo_
·
2017-07-14 19:08
数学思维题
Leetcode
Medium
LeetCode
[LeetCode] Maximum Product
Subarray
求最大子数组乘积
题目描述:输入n个元素组成的序列S,你需要找出一个乘积最大的连续子序列。样例输入:324-3525-12-1样例输出:8201.最简单的思路:暴力枚举枚举每个子序列的乘积,比较它们的乘积代码:#include#definemax(x,y)(x>y?x:y)intmain(){intn,i,a[20];scanf("%d",&n);for(i=0;i#definemax(x,y)(x>y?x:y)#
丁低调
·
2017-07-14 15:14
算法
Continuous
Subarray
Sum (LeetCode Algorithm Problem)
本题主要做的是判断一组序列里面是否有这样一组连续的子序列,他们的和正好能够整除k。我们逐步分析,一个直观的做法是暴力搜索每一个连续的字串,然后把他们相加,看看能否整除k。我们接上述Example1展开,然后我们发现:包含第一个元素的子序列有【23,2】,【23,2,4】,【23,2,4,6】,【23,2,4,6,7】包含第二个元素的子序列有【2,4】,【2,4,6】,【2,4,6,7】包含第三个元
YouyouPan
·
2017-07-04 13:38
leetcode
Lintcode42 Maximum
Subarray
II solution 题解
【题目描述】Givenanarrayofintegers,findtwonon-overlappingsubarrayswhichhavethelargestsum.Thenumberineachsubarrayshouldbecontiguous.Returnthelargestsum.Notice:Thesubarrayshouldcontainatleastonenumber给定一个整数数组
abcdd1234567890
·
2017-06-28 20:42
lintcode
Lintcode41 Maximum
Subarray
solution 题解
【题目描述】Givenanarrayofintegers,findacontiguoussubarraywhichhasthelargestsum.Notice:Thesubarrayshouldcontainatleastonenumber.给定一个整数数组,找到一个具有最大和的子数组,返回其最大和。注意:子数组最少包含一个数【题目链接】http://www.lintcode.com/en/pr
abcdd1234567890
·
2017-06-27 00:29
参考答案
solution
contain
Algorithm Arrays-3 Max Sum Contiguous
Subarray
1.问题:连续子数组最大和Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample:Giventhearray[-2,1,-3,4,-1,2,1,-5,4],thecontiguoussubarray[4,-1,2,1]hasthelargestsum=6.F
toseektruth
·
2017-06-14 19:00
算法
数组
Arrays
最大和
Shortest Unsorted Contimuous
Subarray
classSolution{public:intfindUnsortedSubarray(vector&nums){vectornum_buffer;for(inti=0;i&nums){intshortest=0;intleft=0,right=nums.size()-1;while(left0&&nums[right]>=nums[right-1]){right--;};if(right>le
Yunlong_Luo
·
2017-06-08 14:49
C++
算法
LeetCode
The largest sum of the
subarray
that no more than K
GivenanarrayofintegersAandanintegerk,findasubarraythatcontainsthelargestsum,subjecttoaconstraintthatthesumislessthank?vectorvec={3,4,1,2,4,1,-5};intk=0;intmain(){setseq;intsum=0;intres=INT_MIN;for(aut
shiyang6017
·
2017-06-06 00:00
算法
Maximum
Subarray
Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray[-2,1,-3,4,-1,2,1,-5,4],thecontiguoussubarray[4,-1,2,1]hasthelargestsum=6.解题思路:sum:初始值是数
fight_girl
·
2017-05-30 00:00
Shortest Unsorted Continuous
Subarray
(JAVA)最短未排序数组
581.ShortestUnsortedContinuousSubarrayGivenanintegerarray,youneedtofindonecontinuoussubarraythatifyouonlysortthissubarrayinascendingorder,thenthewholearraywillbesortedinascendingorder,too.Youneedtofin
mine_song
·
2017-05-26 17:16
leetcode
Shortest Unsorted Continuous
Subarray
https://leetcode.com/problems/shortest-unsorted-continuous-
subarray
/#/description找到最短连续子数组,将这个子数组排序之后整个数组就有序了
gqk289
·
2017-05-19 14:50
LeetCode
[LeetCode] Shortest Unsorted Continuous
Subarray
最短无序连续子数组
Givenanintegerarray,youneedtofindonecontinuoussubarraythatifyouonlysortthissubarrayinascendingorder,thenthewholearraywillbesortedinascendingorder,too.Youneedtofindtheshortestsuchsubarrayandoutputitsle
Grandyang
·
2017-05-19 06:00
LeetCode刷题(C++)——Maximum
Subarray
(Easy)
Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray[-2,1,-3,4,-1,2,1,-5,4],thecontiguoussubarray[4,-1,2,1]hasthelargestsum=6.思路:(1)暴力枚举法:起点
YF_Li123
·
2017-05-08 18:09
LeetCode刷题(C++)
一维动态规划及优化(max
subarray
, sell stock, Climbing Stairs)
动态规划(DynamicProgramming)从分治到动态规划:动态规划的基本思想是将待求解的问题分解为若干个子问题,这与分治的思想类似,Paste_Image.png不同的地方在于当子问题之间是相互独立的,这时候分治算法是我们解决问题的最好的思路,因为不同的子问题求解不会有公共的重复计算的地方,然而,当分解得到的子问题不相互独立时,动态规划就是我们最好的选择,我们可以建立一个cache来记录重
王泽强Fantasy
·
2017-05-07 10:28
LeetCode OJ-560.
Subarray
Sum Equals K
LeetCodeOJ-560.SubarraySumEqualsK题目描述Givenanarrayofintegersandanintegerk,youneedtofindthetotalnumberofcontinuoussubarrayswhosesumequalstok.Example1:Input:nums=[1,1,1],k=2Output:2Note:Thelengthofthearr
Morrisss_
·
2017-05-06 15:47
OJ
ACM
OJ
leetcode
子数组和
Subarray
Sum Equals K 子数组和为K
Givenanarrayofintegersandanintegerk,youneedtofindthetotalnumberofcontinuoussubarrayswhosesumequalstok.Example1:Input:nums=[1,1,1],k=2Output:2Note:Thelengthofthearrayisinrange[1,20,000].Therangeofnumbe
Grandyang
·
2017-05-04 22:00
《算法导论》第4章 分治策略 个人笔记
4.1最大子数组问题FIND-MAX-CROSSING-
SUBARRAY
(A,low,mid,high)left_sum=-MAXsum=0fori=middowntolowsum=sum+A[i]ifsum
Amber07
·
2017-05-03 12:05
算法导论
Subarray
Sum Equals K
Givenanarrayofintegersandanintegerk,youneedtofindthetotalnumberofcontinuoussubarrayswhosesumequalstok.Example1:Input:nums=[1,1,1],k=2Output:2Note:Thelengthofthearrayisinrange[1,20,000].Therangeofnumbe
TstsUgeg
·
2017-05-03 10:51
leetcode
Subarray
Sum Equals K
问题描述:Givenanarrayofintegersandanintegerk,youneedtofindthetotalnumberofcontinuoussubarrayswhosesumequalstok.Example1:Input:nums=[1,1,1],k=2Output:2思路:记录从开始到位置i的累加和,再统计位置i之前有多少个累加和等于sum[i]-k.代码:classSol
obudunkey
·
2017-05-02 19:05
leetcode
Subarray
Sum Equals K
这是weeklytest30的第二题。bruteforce用bruteforce的话就是从每个数字向前或向后遍历,减去当前值,等于0就count++,不需要中断,因为有可能000000,k=0这种情况,而且什么时候中断也不好判断。。Time是O(n^2)。用Java能过,python好像会TLE。publicintsubarraySum(int[]nums,intk){intres=0;if(nu
DrunkPian0
·
2017-04-30 18:26
算法-Maximum
Subarray
: a simpler solution
原题Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray[-2,1,-3,4,-1,2,1,-5,4], thecontiguoussubarray[4,-1,2,1]hasthelargestsum=6.代码实现publici
daigualu
·
2017-04-29 17:00
LeetCode
array
simulate
max-subary
leetcode53 Maximum
Subarray
最大连续子数组
题目要求Findthecontiguoussubarraywithinanarray(containingatleastonenumber)whichhasthelargestsum.Forexample,giventhearray[-2,1,-3,4,-1,2,1,-5,4],thecontiguoussubarray[4,-1,2,1]hasthelargestsum=6.即:寻找数列中的一个
raledong
·
2017-04-13 00:00
leetcode
java
divide-conquer
recursion
LeetCode - Maximum
Subarray
原题网址:https://leetcode.com/problems/maximum-
subarray
/#/descriptionFindthecontiguoussubarraywithinanarray
marywbrown
·
2017-04-04 16:23
Algorithm
design
&
Leetcod
Continuous
Subarray
Sum
Givenalistofnon-negativenumbersandatargetintegerk,writeafunctiontocheckifthearrayhasacontinuoussubarrayofsizeatleast2thatsumsuptothemultipleofk,thatis,sumsupton*kwherenisalsoaninteger.Example1:Input:[
TstsUgeg
·
2017-03-27 16:17
leetcode
上一页
17
18
19
20
21
22
23
24
下一页
按字母分类:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
其他