Пример #1
0
        public static Triplet GetTripletThatReachTarget(int[] numbers, int target)
        {
            for (var i = 0; i < numbers.Length; i++)
            {
                for (var j = 0; j < numbers.Length; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    for (var k = 0; k < numbers.Length; k++)
                    {
                        if (i == k || j == k)
                        {
                            continue;
                        }

                        var triplet = new Triplet(numbers[i], numbers[j], numbers[k]);
                        if (triplet.Add() == target)
                        {
                            return(triplet);
                        }
                    }
                }
            }

            return(new (0, 0, 0));
        }