My AC and Easy understanding solution! 14ms


  • 0
    D

    public int findCelebrity(int n) {
    for (int i=0;i<n;++i) {
    int count = 0;
    for (int j=0;j<n;++j) {
    if (i==j) {
    continue;
    }
    if(knows(j,i)&&!knows(i,j)) {
    count++;
    } else {
    break;
    }
    }
    if (count==n-1) {
    return i;
    }
    }
    return -1;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.