When I try to compare the current state of j and nums[i+1], it says "List index out of range". But I saw the other post did the same and worked compare current item to next item in a python list Why?
class Solution:
def majorityElement(self, nums: List[int]) -> int:
nums.sort()
count = -1
for i,j in enumerate(nums):
count += 1
if count > len(nums) / 2:
return nums[i]
if j != nums[i+1]:
count = 0