LeetCode – Majority Element II (Java)

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. Java Solution This problem is similar to Majority Element I. Time = O(n) and Space = O(1). public List<Integer> majorityElement(int[] nums) { List<Integer> result = new … Read more