AC python 1 line nlogn time


  • 12
    S
    class Solution:
        # @param num, a list of integers
        # @return an integer
        def majorityElement(self, num):
            return sorted(num)[len(num)/2]

  • 0
    C

    I like this. I completely didn't realize that the major element will be in the n/2's slot. Instead of getting the length of each repeated element, simply go for the n/2 spot.


  • 0
    T

    Very nice code!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.