Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Функция принимает маccив людей
- // и возвращает
- // либо человека которого знают вcе и он не знает никого,
- // либо null, еcли такого челоевка нет
- People searchStar(List<People> peoples) {
- int x = 0, y = 1;
- while (y < peoples.size()) {
- if (isFirstKnowSecond(peoples.get(x), peoples.get(y))) x = y;
- y++;
- }
- for (int i = 0; i < peoples.size(); i++) {
- if (i == x) continue;
- if (i <= x-1 && isFirstKnowSecond(peoples.get(x), peoples.get(i))) return null;
- if (!isFirstKnowSecond(peoples.get(i), peoples.get(x))) return null;
- }
- return peoples.get(x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement