Skip to content

Instantly share code, notes, and snippets.

@adamkorg
Created April 21, 2020 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamkorg/22b1eee179d42a5c0cf4fc32efc8c573 to your computer and use it in GitHub Desktop.
Save adamkorg/22b1eee179d42a5c0cf4fc32efc8c573 to your computer and use it in GitHub Desktop.
Leetcode 277: Find the Celebrity (O(n^2))
#include <iostream>
using namespace std;
bool knows(int a, int b);
int findCelebrity(int n) {
for (int b=0; b<n; ++b) {
int count=0;
for (int a=0; a<n; ++n) {
if (knows(a,b)) count++;
else break;
}
if (count == n) return b;
}
return -1;
}
//not runnable, requires leetcode knows() function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment