Created
April 21, 2020 22:11
-
-
Save adamkorg/22b1eee179d42a5c0cf4fc32efc8c573 to your computer and use it in GitHub Desktop.
Leetcode 277: Find the Celebrity (O(n^2))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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