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"); } } } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
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 ..)