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的更多相关文章

  1. 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 ...

  2. Data Structure Array: Move all zeroes to end of array

    http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...

  3. 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 ...

  4. Data Structure Array: Sort elements by frequency

    http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/ #include <iostream> #include &l ...

  5. Data Structure Array: Maximum circular subarray sum

    http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...

  6. 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& ...

  7. 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 ...

  8. Data Structure Array: Longest Monotonically Increasing Subsequence Size

    http://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/ #include < ...

  9. Data Structure Array: Find the minimum distance between two numbers

    http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/ #include <iostream> ...

随机推荐

  1. MySQL中创建用户分配权限

    测试环境:CentOS6.8 和 MySQL5.5.4 一 需求 在项目开发的过程中可能需要开放自己的数据库给别人,但是出于安全的考虑,不能同时开放自己服务器里的其他数据库.那么可以新建一个用户,赋予 ...

  2. shell脚本通过ping命令来获取平均延时

    #!/bin/bash #设置环境变量 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin" exp ...

  3. vs 2015 update 3各版本下载地址

    微软在06月27日发布了Visual Studio 2015 Update 3 .在MSDN中微软也提供下载,而且MSDN的Visual Studio 2015 Update 3与官方免费下载的文件是 ...

  4. 修改eclipse的repository路径

    (1)首先修改你的settings.xml文件,(如果没有settings.xml文件,可以下载maven的官网把maven的插件下载下来,在apache-maven-3.5.0\conf\ 目录下有 ...

  5. 事件驱动模型实例详解(Java篇)

    或许每个软件从业者都有从学习控制台应用程序到学习可视化编程的转变过程,控制台应用程序的优点在于可以方便的练习某个语言的语法和开发习惯(如.net和java),而可视化编程的学习又可以非常方便开发出各类 ...

  6. 第二篇: Ansible 安装

    一.配置epel源 wget –O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo 二.安装ansible  ...

  7. e.target与e.currentTarget对比

    复制以下代码,即可查看效果 <!DOCTYPE html> <html> <head lang="en"> <meta charset=& ...

  8. PYTHON测试邮件系统弱密码

    #-*- coding:utf-8 -*- #测试公司邮件系统弱密码, from email.mime.text import MIMEText import smtplib #弱密码字典 passL ...

  9. git入门三(远程、标签)

    git 入门三 (远程.标签)     分布式版本控制管理系统本地仓库和中心服务器仓库数据是本地的镜像仓库,中心服务器数据仓库的是为了多用户数据合并和获取同步的中心,多人协作需要管理这些远程仓库,以便 ...

  10. cf 251 B Playing with Permutations 暴力 分类讨论

    题链;http://codeforces.com/problemset/problem/251/B B. Playing with Permutations time limit per test 2 ...