Could anyone explain to me why calling this function does not work? It shows I have an error from ContainsDuplicate in main (ContainsDuplicate does not exist in current context).
static void Main(string[] args)
{
var result = ContainsDuplicate(new int[] { 1, 2, 3, 4, 5, 1 });
Console.WriteLine(result);
}
public class solution {
public bool ContainsDuplicate(int[] nums)
{
var hash = new HashSet<int>();
foreach (var i in nums)
{
if (hash.Add(i)) return true;
}
return false;
}