The requested element can be return when it is dealt with. It saves running time.

```
public class Solution {
public int majorityElement(int[] num) {
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
if(num.length == 1) return num[0];
for(int i=0; i<num.length; i++) {
if(!hm.containsKey(num[i])) {
hm.put(num[i], 1);
} else {
hm.put(num[i], hm.get(num[i])+1);
if(hm.get(num[i]) > num.length/2) return num[i];
}
}
return -1;
}
}
```