Majority Element - Leetcode 169 - Hashmaps & Sets (Python)

preview_player
Показать описание


Please check my playlists for free DSA problem solutions:

My Favorite Courses:

Data Structures & Algorithms:

Python:

Web Dev / Full Stack:

Cloud Development:

Game Development:

SQL & Data Science:

Machine Learning & AI:
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

I follow neetcode, but not every explanation of his understandable for me, but your is defferent. Your explanation is awesome. Great Greatt !!!!

moein
Автор

Hi, thanks for the video. The solution is not working with such array [2, 2, 1, 3, 3, 2, 3, 2, 3, 1, 1, 1, 1, 2, 2], so I assume that the variant with HashSet is better in this case.
Thanks.

artemborysenko
Автор

h = Counter(nums)
return max(h, key = h.get)

Channel_SPS
Автор

The majority elements count cant be reduced completely by any other elements count and finally the majority element will be having enough count to be in the ans variable even after checking all other elements

Fastforwardj
Автор

why did you give it a Difficulty score of 8 in algomap

mamineamin
Автор

This is an implementation of Kadane's Algorithm right?

mbe
Автор

count = collections.Counter(nums)
majority_ele = max(count.values())

for n in nums:
if count[n] == majority_ele:
return n
can we do this i did this and leetcode accepted the solution

vidhansaini
Автор

Calling it "count" in the second example is misleading. Its more like a weight or something like that. :D

Blafasel
Автор

wtf lol why is this working, and who the heck came up with this confusing but smart solution

hamids