Data Structure Array: Find if there is a subarray with 0 sum
http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
#include <set>
using namespace std; bool zerosubarray(int arr[], int n) {
set<int> S;
int sum = ;
for (int i = ; i < n; i++) {
sum += arr[i];
if (arr[i] == || sum == || S.find(sum) != S.end()) return true;
S.insert(sum);
}
return false;
} int main() {
int arr[] = {, , -, , };
if (zerosubarray(arr, )) cout << "yes" << endl;
else cout << "no" << endl;
return ;
}
Data Structure Array: Find if there is a subarray with 0 sum的更多相关文章
- Data Structure Array: Find the Missing Number
http://www.geeksforgeeks.org/find-the-missing-number/ 1. use sum formula, O(n), O(1) 2. use XOR, O(n ...
- Data Structure Array: Move all zeroes to end of array
http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...
- Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times
http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-tha ...
- Data Structure Array: Sort elements by frequency
http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/ #include <iostream> #include &l ...
- Data Structure Array: Maximum circular subarray sum
http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...
- Data Structure Array: Largest subarray with equal number of 0s and 1s
http://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s/ #include <iostream& ...
- Data Structure Array: Find the two numbers with odd occurrences in an unsorted array
http://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/ #include ...
- Data Structure Array: Longest Monotonically Increasing Subsequence Size
http://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/ #include < ...
- Data Structure Array: Find the minimum distance between two numbers
http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/ #include <iostream> ...
随机推荐
- Android 下Service
1 http://www.cnblogs.com/newcj/archive/2011/05/30/2061370.html 2 http://blog.csdn.net/android_tutor/ ...
- requests ssl 报错
使用requests下载日志出现HTTPSConnectionPool(host='***', port=443): Max retries exceeded with url: ******(Cau ...
- linux 下mtime,ctime,atime分析
一.atime.ctime与mtime atime是指access time,即文件被读取或者执行的时间,修改文件是不会改变access time的.网上很多资料都声称cat.more等读取文件的命令 ...
- hector_localization hector_salm rplidar同时编译
1.将hector_localization包clone到src文件夹 进行功能包依赖安装 cd test_ws rosdep update rosdep install --from-paths ...
- Selenium3.X 与 Javascript (Nodejs)
传送门 # 官网网站 http://docs.seleniumhq.org/download/ # API DOC http://goo.gl/hohAut # 慕课网教程http://www.imo ...
- C# 缓存技术
缓存主要是为了提高数据的读取速度.因为服务器和应用客户端之间存在着流量的瓶颈,所以读取大容量数据时,使用缓存来直接为客户端服务,可以减少客户端与服务器端的数据交互,从而大大提高程序的性能. 本章从缓存 ...
- 【安装.net framework4.0】之安装失败,“安装时发生严重错误”
在网上查了很多资料都说改什么文件名和注册表什么的,根本没用,后来查到一篇文章,提供了下面的解决办法: 地址:<Microsoft .NET Framework 4.0安装时发生严重错误 无法安装 ...
- Mac OS X 安装Ruby
安装CocoaPods第一步 起因:重装系统后需要重新安装CocoaPods网上搜了下发现很多都过时了,已经不能用了.而且taobao Gems源已经停止服务,现在有ruby-china提供服务 PS ...
- 关于使用eclipse开发最小运行组件包
有的时候向用eclipse组件,但是其中好多东西是相互关联的,如果在eclipse上做二次开发固然可以,但是有的时候想要的只不过是一个可以运行的架包而已,所以不必要那么多东西. 下面是我使用eclip ...
- iptables基础及samba配置举例
iptable基本概念 iptables防火墙包含两部分,即位于用户空间的iptables模块和位于内核空间netfilter模块.用户空间模块提供插入.修改和除去包过滤表中规则,内核模块进行实际的过 ...