Last active
February 14, 2024 06:42
-
-
Save unilecs/78f9a9b725fe26a881f0cab0da531dfe to your computer and use it in GitHub Desktop.
Задача: Пункт назначения
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
using System; | |
using System.Collections.Generic; | |
public class Program | |
{ | |
public static string DestinationCity(IList<IList<string>> paths) { | |
int len = paths.Count; | |
// частный случай | |
if (len == 1) { | |
return paths[0][1]; | |
} | |
// запоминаем все города отправления | |
var set = new HashSet<string>(); | |
for(int i = 0; i < len; i++) | |
{ | |
set.Add(paths[i][0]); | |
} | |
// находим 1й город назначения | |
for(int i = 0; i < len; i++) | |
{ | |
if (!set.Contains(paths[i][1])) { | |
return paths[i][1]; | |
} | |
} | |
return ""; | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
// tests | |
var list1 = new List<IList<string>>() | |
{ | |
new List<string>() { "B","C" }, | |
new List<string>() { "D", "B" }, | |
new List<string>() { "C", "A" } | |
}; | |
Console.WriteLine(DestinationCity(list1)); // "A" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment