The approach is to check every pair of array. If two elements of pair are equal than we store the value in the array from the begining. The process should be repeated while the lenght of the array is 1 or 2. If 2 elements remain so we should count one of them to find a major.

```
public int majorityElement(int[] num) {
int[] numCopy = new int[num.length];
System.arraycopy(num, 0, numCopy, 0, num.length);
int i = num.length;
int j = 0;
// Find one or two major candidates.
while(i > 2) {
for (int k=0; k<i; k+=2) {
if (k+1 < i) {
if (num[k] == num[k+1]) {
num[j] = num[k];
j++;
}
} else {
num[j] = num[k];
j++;
}
}
i = j;
j = 0;
}
// Count if there are two candidates
// ore return if there is only one candidate
if (i == 2) {
int count = 0;
for (int k=0; k<numCopy.length; k++) {
if (numCopy[k] == num[0]) {
count ++;
}
}
if (count>numCopy.length/2) {
return num[0];
} else {
return num[1];
}
} else {
return num[0];
}
}
```