This is the code I retrieved from the submission bar graph, currently it's the best-performing Java algorithm. I cleaned the code up a little and re-verified its speed, and it's still 1ms and beats 99.91%.

I am not very experienced with algorithms and I find this code hard to understand, can anyone shed some light? Also, this code looks like tail-recursion, how would one go about rewriting it to an iterative version?

```
public class Solution {
public int majorityElement(int[] nums) {
return maj(nums, nums.length);
}
public int maj(int[] nums, int n) {
if (n == 1 || n == 2) return nums[0];
int p = 0;
for (int i = 0 ; i < n; i = i + 2) {
if (i == n - 1 || nums[i] == nums[i + 1]) {
nums[p++] = nums[i];
}
}
return maj(nums,p);
}
}
```

Thanks for any help offered.

====update 2017-06-29 16:50:36====

cleared the code a little bit more.