The standard library contains the right function for this problem:

```
int majorityElement(vector<int> &num) {
nth_element(num.begin(), num.begin() + (num.size() / 2), num.end());
return num[num.size() / 2];
}
```

O(N), no extra space (not even constant extra space) and just two lines of code.