博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CareerCup Given an array having positive integers, find a subarray which adds to a given number
阅读量:4184 次
发布时间:2019-05-26

本文共 650 字,大约阅读时间需要 2 分钟。

Given an array having positive integers, find a continous subarray which adds to a given number.

-----------------------------------------------

Take notice that all numbers are positive!

It can be done O(n). 
My logic is as follows:- Keep adding elements to a running sum till it is either equal to given number or is greater than the given number. As soon as we add a number and the running number is greater than the given number we subtract the elements from the beginning of the array till it is again less than the given number. After the current sum is less than the given number we add the next element and check and continue the same process.

转载地址:http://pzboi.baihongyu.com/

你可能感兴趣的文章
关于JVM内存区域的组成以及堆内存的回收原理
查看>>
JVM的垃圾回收机制以及回收策略随记
查看>>
生成XML的方法
查看>>
Reactor模式
查看>>
Connector configured to listen on port 8080 failed to start
查看>>
注解的使用
查看>>
【转】inet_addr、inet_aton、inet_pton异同小结
查看>>
linux中绑定80端口失败
查看>>
关于链接失败 对xxxx ‘__gxx_personality_v0’未定义的引用
查看>>
关于char*类型返回值和字符串常量
查看>>
epoll的一些关键点和总结(一)
查看>>
epoll的一些关键点和总结(二)
查看>>
关于epoll边缘触发模式(ET)下的EPOLLOUT触发
查看>>
socket TCP编程中connect的一些坑
查看>>
从C++单例模式到线程安全
查看>>
浅谈C文件编译过程
查看>>
FOJ 1001之位图数据结构对程序的优化
查看>>
盛名之下,其实难副?——再读CMU巨著CSAPP
查看>>
Python 解压稀疏矩阵
查看>>
Go 交换切片内两个索引对应的值
查看>>