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> ...
随机推荐
- 遍历list,字典
private void Form1_Load(object sender, EventArgs e) { List<int> ids = new List<int>(); i ...
- nightwatch-js ----并发运行
从v0.5开始nightwatch支持并发测试.通过在命令行中指定多个环境来工作,用逗号分隔.例如: $ nightwatch -e default,chrome 这样可以在多个相同或是不同的浏览器上 ...
- java之Cookie具体解释
Cookie是由server端生成.发送给User-Agent(通常是浏览器).浏览器会将Cookie的key/value保存到某个文件夹下的文本文件内.下次请求同一站点时就发送该Cookie给ser ...
- Android的View 事件传递
欢迎转载,请附出处: http://blog.csdn.net/as02446418/article/details/47422891 1.基础知识 (1) 全部 Touch 事件都被封装成了 Mot ...
- C#中YieldReturn的用法
Yield Return 和 Yield Break 的出现是为了简化迭代器. 类如果能被遍历则必须有IEnumerator<string> GetEnumerator() 方法, 并有用 ...
- [转载]Axure RP 7.0下载地址及安装说明
Axure RP是产品经理必备的原型制作工具,因为很多同学是新手,在这里整理一下axure7.0的下载.安装和汉化流程,希望能够帮到大家. Axure RP是美国Axure Software Solu ...
- php正則表達式中的非贪婪模式匹配的使用
php正則表達式中的非贪婪模式匹配的使用 通常我们会这么写: $str = "http://www.baidu/.com? url=www.sina.com/"; preg_mat ...
- Unity UGUI——提供可视功能的UI组件(Text)
基本属性介绍 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTXJfQUhhbw==/font/5a6L5L2T/fontsize/400/fill/I0J ...
- spring download
http://maven.springframework.org/release/org/springframework/spring/
- simple_pool对象池——优化<二>
本文章由cartzhang编写.转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/55051570 作者:car ...