Majority Element II | Moore's Voting Algorithm | Leetcode 229 | September Challenge
Автор: Shantanu Nandi
Загружено: 2020-09-22
Просмотров: 94
Описание:
September LeetCoding Challenge | Problem 22 | Majority Element II | 22 September,
Facebook Coding Interview question,
Google Coding Interview question,
Microsoft Coding Interview question,
Leetcode 229,
Majority Element II
#MooreVotingAlgorithm #CodingInterview #LeetCode #SeptemberCodingChallenge #Google #Amazon #Microsoft
Moore’s Voting Algorithm:
------------------------
Step 1: The first step gives the element that maybe the majority element in the array.
Step 2: Check if the element obtained from the above step is majority element.
Pseudo code:
------------
Initialise majority = 0 and count = 0
For each element current of input sequence:
If count = 0:
set majority = current and count = 1
Else if majority = current:
increment count by 1
Else
decrement count
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: