| | | 1 | | // -------------------------------------------------------------------------------- |
| | | 2 | | // Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | | 3 | | // All Rights Reserved. |
| | | 4 | | // -------------------------------------------------------------------------------- |
| | | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | | 9 | | // known as Yevhenii Yeriemeieiv). |
| | | 10 | | // -------------------------------------------------------------------------------- |
| | | 11 | | |
| | | 12 | | namespace LeetCode.Algorithms.FindingThreeDigitEvenNumbers; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public sealed class FindingThreeDigitEvenNumbersBruteForce : IFindingThreeDigitEvenNumbers |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Time complexity - O(n^3 + M log M) |
| | | 19 | | /// Space complexity - O(M) |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="digits"></param> |
| | | 22 | | /// <returns></returns> |
| | | 23 | | public int[] FindEvenNumbers(int[] digits) |
| | 3 | 24 | | { |
| | 3 | 25 | | var numbersHashSet = new HashSet<int>(); |
| | | 26 | | |
| | 30 | 27 | | for (var i = 0; i < digits.Length; i++) |
| | 12 | 28 | | { |
| | 12 | 29 | | if (digits[i] == 0) |
| | 1 | 30 | | { |
| | 1 | 31 | | continue; |
| | | 32 | | } |
| | | 33 | | |
| | 114 | 34 | | for (var j = 0; j < digits.Length; j++) |
| | 46 | 35 | | { |
| | 46 | 36 | | if (j == i) |
| | 11 | 37 | | { |
| | 11 | 38 | | continue; |
| | | 39 | | } |
| | | 40 | | |
| | 378 | 41 | | for (var k = 0; k < digits.Length; k++) |
| | 154 | 42 | | { |
| | 154 | 43 | | if (k == i || k == j || digits[k] % 2 == 1) |
| | 84 | 44 | | { |
| | 84 | 45 | | continue; |
| | | 46 | | } |
| | | 47 | | |
| | 70 | 48 | | numbersHashSet.Add((digits[i] * 100) + (digits[j] * 10) + digits[k]); |
| | 70 | 49 | | } |
| | 35 | 50 | | } |
| | 11 | 51 | | } |
| | | 52 | | |
| | 3 | 53 | | var result = numbersHashSet.ToArray(); |
| | | 54 | | |
| | 3 | 55 | | Array.Sort(result); |
| | | 56 | | |
| | 3 | 57 | | return result; |
| | 3 | 58 | | } |
| | | 59 | | } |