(算法设计技巧与分析)Majority
来源:互联网 发布:淘宝卖家恶意不发货 编辑:程序博客网 时间:2024/06/04 06:33
#include<iostream>using namespace std;int Condidate(int a[],int n,int j);int main(){int count=0;int a[12]={1,1,1,1,1,1,2,2,2,2,2,2};int c=Condidate(a,12,0);for(int i=0;i<12;i++)if(a[i]==c)count++;if(count>11/2)cout<<"The majority in the array is "<<c<<endl;else cout<<"no majority!";return 0;}int Condidate(int a[],int n,int j){int x=a[j];int count=1;while(j<n&&count>0)if(a[++j]==x)count++;else count--;if(j==n)return x;else return Condidate(a,n,j+1);}
0 0
- (算法设计技巧与分析)Majority
- 算法分析与设计:leetcode169.Majority Element
- 【算法分析与设计】【第五周】169. Majority Element
- (算法设计技巧与分析)LinearSearch
- (算法设计技巧与分析)BinarySearch
- (算法设计技巧与分析)Merge
- (算法设计技巧与分析)SelectSort
- (算法设计技巧与分析)InsertionSort
- (算法设计技巧与分析)SelectionSortFec
- (算法设计技巧与分析)InsertionSort
- (算法设计技巧与分析)RadixSort
- (算法设计技巧与分析)Exprec
- (算法设计技巧与分析)Permutationsi
- (算法设计技巧与分析)MinMax
- (算法设计技巧与分析)BinarySearchrec
- (算法设计技巧与分析)MergeSort
- (算法设计技巧与分析)QuickSort
- (算法设计技巧与分析)CloseStpair
- PKI常见证书格式和转换
- MFC 串口编程总结
- oracle函数参数中=>的含义
- 获取request请求路径信息
- 统计单词出现的次数
- (算法设计技巧与分析)Majority
- LeetCode #58 length of Last Word
- linux fstab 使用指南
- hbase数据库错误总结 ——ERROR: Can't get master address from ZooKeeper; znode data == null
- ScrollView中图片的无限轮播(精简)
- iOS基础程序Demo
- 友坚三星4412开发板Linux平台下UT4412BV03裸机开发指南
- xxx定律 (1031)
- (算法设计技巧与分析)MinMax