Codility-EquiLeader
来源:互联网 发布:java高并发的解决方案 编辑:程序博客网 时间:2024/06/09 16:23
A non-empty zero-indexed array A consisting of N integers is given.
The leader of this array is the value that occurs in more than half of the elements of A.
An equi leader is an index S such that 0 ≤ S < N − 1 and two sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N − 1] have leaders of the same value.
For example, given array A such that:
A[0] = 4 A[1] = 3 A[2] = 4 A[3] = 4 A[4] = 4 A[5] = 2
we can find two equi leaders:
- 0, because sequences: (4) and (3, 4, 4, 4, 2) have the same leader, whose value is 4.
- 2, because sequences: (4, 3, 4) and (4, 4, 2) have the same leader, whose value is 4.
The goal is to count the number of equi leaders. Write a function:
int solution(vector<int> &A);
that, given a non-empty zero-indexed array A consisting of N integers, returns the number of equi leaders.
For example, given:
A[0] = 4 A[1] = 3 A[2] = 4 A[3] = 4 A[4] = 4 A[5] = 2
the function should return 2, as explained above.
Assume that:
- N is an integer within the range [1..100,000];
- each element of array A is an integer within the range [−1,000,000,000..1,000,000,000].
Complexity:
- expected worst-case time complexity is O(N);
- expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).
Elements of input arrays can be modified.
- Codility-EquiLeader
- codility EquiLeader
- [codility] EquiLeader解题报告
- codility
- codility
- Codility -- Fish
- Codility -- Brackets
- Codility -- grocery_store
- Codility -- Triangle
- [codility]Triangle
- [codility]Brackets
- [codility]Fish
- [codility]Dominator
- [codility]Equi
- [codility]equi
- [codility]MinAbsSumOfTwo
- [codility]CountMultiplicativePairs
- 【Codility】PassingCars
- 读《谁说菜鸟不会数据分析》之笔记1
- 获取a元素的文本内容
- 信息学试题分类
- JDBC学习第二站之ResultSet与ResultSetMeta
- 输入数字n,按顺序输出从1最大的n位10进制数。比如输入3,则输出1、2、3一直到最大的3位数即999
- Codility-EquiLeader
- 【实践驱动开发3-004】TI WL1835MODCOM8 在android的移植 - 系统结构初始化和参考列表
- hdu2063过山车
- getline()函数详解 (2013-03-26 17:19:58)
- TOJ 1144. Tree Recovery
- YII CListView 分页 另一种写法
- hdu2850Load Balancing 贪心+优先队列
- usaco3.2.4纺车的轮子
- javaWeb中URLEncoder.encode空格问题