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>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; void findsubarray(int arr[], int n) {
map<int, vector<int> > S;
int sum = ;
for (int i = ; i < n; i++) {
sum += (arr[i] == ? - : );
if (S.find(sum) != S.end()) S[sum].push_back(i);
else S[sum] = vector<int>(, i);
}
int ans = ;
for (map<int, vector<int> >::iterator it = S.begin(); it != S.end(); it++) {
if ((it->first) == ) ans = max(ans, (it->second)[(it->second).size()-]+);
else ans = max(ans, (it->second)[(it->second).size()-] - (it->second)[]);
}
cout << ans << endl;
} int main() {
int arr[] = {, , , , , , };
findsubarray(arr, );
return ;
}
Data Structure Array: Largest subarray with equal number of 0s and 1s的更多相关文章
- 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: Find if there is a subarray with 0 sum
http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ #include <iostream> #incl ...
- 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: Maximum circular subarray sum
http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...
- 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: Sort elements by frequency
http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/ #include <iostream> #include &l ...
- 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> ...
随机推荐
- handlebars.js基础学习笔记
最近在帮学校做个课程网站,就有人推荐用jquery+ajax+handlebars做网站前端,刚接触发现挺高大上的,于是就把一些基础学习笔记记录下来啦. 1.引用文件: jquery.js文件下载:h ...
- 借助Anyproxy实时监控接口调用次数和流量
监控接口调用次数,是为了测试客户端可能会异常频繁的调用服务端接口,出现性能问题. AnyProxy是一个开放式的HTTP代理服务器. github: https://github.com/alibab ...
- debian SSD ext4 4K 对齐
新入手了一台thinkpad, 原来的机械硬盘是500G的, 于是购入一块镁光的MX200 250G的SSD来新装debian stable(jessie) 1, 安装系统的之前按住F1进入bios后 ...
- C语言小板凳(1)
①strlen()函数作用:计算字符串的长度,当遇到"\n"字符时结束,即遇到数值"0"时结束计算,有一点特别要注意当这个函数用来计算数组的长度的时候遇到数值0 ...
- [译]GLUT教程 - 整合代码4
Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> The Code So Far IV 以下代码使用了位图字 ...
- Quartz.Net - Lesson2: 任务和触发器
Lesson 2: 任务和触发器 本系列文章是官方3.x文档的翻译,原文地址:https://www.quartz-scheduler.net/documentation/quartz-3.x/tut ...
- HUAWEI HiAI亮相Droidcon柏林2018开发者峰会 开启HiAI海外生态
柏林时间6月25日到27日,华为HiAI亮相Droidcon柏林2018开发者峰会,有1200多位海外开发者参加了此次峰会,来自HUAWEI HiAI领域的多名专家携手Prisma和金山WPS,以“E ...
- 浅析Apache中RewriteCond规则参数的详细介绍
RewriteCond就像我们程序中的if语句一样,表示如果符合某个或某几个条件则执行RewriteCond下面紧邻的RewriteRule语句,这就是RewriteCond最原始.基础的功能,为了方 ...
- cobbler+koan
cobbler+koan自动重装客户机 koan是kickstart-over-a-network的缩写,它是cobbler的客户端帮助程序,koan允许你通过网络提供虚拟机,也允许你重装已经存在 ...
- erlang的非平衡的二叉树的操作
-module(tree1). -export([test1/0]). lookup(Key,nil) -> not_found; lookup(Key,{Key,Value,_,_}) -&g ...