We're a place where coders share, stay up-to-date and grow their careers.
My solution in C#: (The timer is just for fun ..)
public static void Execute() { var timer = new Stopwatch(); timer.Start(); for (int i = 0; i < input.Count; i++) { for (int i2 = i + 1; i2 < input.Count; i2++) { var valueneeded = 2020 - input[i] - input[i2]; if (input.Contains(valueneeded)) { timer.Stop(); Console.WriteLine(); Console.WriteLine($"Answer: {input[i] * input[i2] * valueneeded}"); Console.WriteLine($"Executed in: {timer.ElapsedMilliseconds} milliseconds, {timer.ElapsedTicks} Ticks"); } } } }
My solution in C#: (The timer is just for fun ..)