```
int findCelebrity(int n) {
for (int i = 0, j = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i != j && knows(i, j)) break; //if i knows j, i is not celebrity
if (i != j && !knows(j, i)) break; //if j don't know i, not celebrity
}
if (j == n) return i; //i does not know any j , but all j know i
}
return -1;
}
```