-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay42.java
More file actions
32 lines (28 loc) · 845 Bytes
/
Day42.java
File metadata and controls
32 lines (28 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Celebrity {
boolean knows(int A, int B) {
return true;
}
int findCelebrity(int N) {
int candidate = 0;
for (int i = 1; i < N; i++) {
if (knows(candidate, i)) {
candidate = i;
}
}
for (int i = 0; i < N; i++) {
if (i != candidate && (knows(candidate, i) || !knows(i, candidate))) {
return -1;
}
}
return candidate;
}
public static void main(String[] args) {
Celebrity celebrityFinder = new Celebrity();
int N1 = 2;
int result1 = celebrityFinder.findCelebrity(N1);
System.out.println("Example 1: " + result1);
int N2 = 2;
int result2 = celebrityFinder.findCelebrity(N2);
System.out.println("Example 2: " + result2);
}
}