Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Create Boyer-Moore Majority Voting Algorithm (C++) #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
Loading
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update majority-element.cpp
  • Loading branch information
bose-aritra2003 authored Jul 2, 2022
commit a18cad1f5bd6a10796cc7879861f1c7d01f6e3f7
5 changes: 3 additions & 2 deletions 5 Competitive Coding/Search/majority-element.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// C++ implementation of Boyer-Moore Majority Voting Algorithm
#include <iostream>
using namespace std;

// Function to find majority element
int findMajority(int arr[], int n)
{
Expand All @@ -21,15 +22,15 @@ int findMajority(int arr[], int n)
int count = 0;
// Checking if majority candidate occurs more than n/2
// times
for (i = 0; i < n; i++) {
for (i = 0; i < n; i++)
if (arr[i] == candidate)
count++;
}

if (count > n / 2)
return candidate;
return -1;
}

int main()
{
int arr[] = { 1, 1, 1, 1, 2, 3, 4 };
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.