Exemplo n.º 1
0
        public void SlidingWindowMaximum_Solutions()
        {
            //Input: nums = [1, 3, -1, -3, 5, 3, 6, 7], and k = 3
            //Output: [3, 3, 5, 5, 6, 7]

            AssertEnumerable.AreEqual(new[] { 3, 3, 5, 5, 6, 7 }, MaxSlidingWindow(new[] { 1, 3, -1, -3, 5, 3, 6, 7 }, 3));
        }
Exemplo n.º 2
0
        public void TwoSum_Solutions()
        {
            AssertEnumerable.AreEqual(new[] { 1, 2 }, TwoSum(new[] { 3, 2, 4 }, 6));

            AssertEnumerable.AreEqual(new[] { 83, 239 }, TwoSum(new[]
            {
                572, 815, 387, 418, 434, 530, 376, 190, 196, 74, 830, 561, 973, 771, 640, 37, 539, 369, 327, 51,
                623, 575, 988, 44, 659, 48, 22, 776, 487, 873, 486, 169, 499, 82, 128, 31, 386, 691, 553, 848, 968,
                874, 692, 404, 463, 285, 745, 631, 304, 271, 40, 921, 733, 56, 883, 517, 99, 580, 55, 81, 232, 971,
                561, 683, 806, 994, 823, 219, 315, 564, 997, 976, 158, 208, 851, 206, 101, 989, 542, 985, 940, 116,
                153, 47, 806, 944, 337, 903, 712, 138, 236, 777, 630, 912, 22, 140, 525, 270, 997, 763, 812, 597,
                806, 423, 869, 926, 344, 494, 858, 519, 389, 627, 517, 964, 74, 432, 730, 843, 673, 985, 819, 397,
                607, 34, 948, 648, 43, 212, 950, 235, 995, 76, 439, 614, 203, 313, 180, 760, 210, 813, 920, 229,
                615, 730, 359, 863, 678, 43, 293, 978, 305, 106, 797, 769, 3, 700, 945, 135, 430, 965, 762, 479,
                152, 121, 935, 809, 101, 271, 428, 608, 8, 983, 758, 662, 755, 190, 632, 792, 789, 174, 869, 622,
                885, 626, 310, 128, 233, 82, 223, 339, 771, 741, 227, 131, 85, 51, 361, 343, 641, 568, 922, 145,
                256, 177, 329, 959, 991, 293, 850, 858, 76, 291, 134, 254, 956, 971, 718, 391, 336, 899, 206, 642,
                254, 851, 274, 239, 538, 418, 21, 232, 706, 275, 615, 568, 714, 234, 567, 994, 368, 54, 744, 498,
                380, 594, 415, 286, 260, 582, 522, 795, 261, 437, 292, 887, 405, 293, 946, 678, 686, 682, 501, 238,
                245, 380, 218, 591, 722, 519, 770, 359, 340, 215, 151, 368, 356, 795, 91, 250, 413, 970, 37, 941,
                356, 648, 594, 513, 484, 364, 484, 909, 292, 501, 59, 982, 686, 827, 461, 60, 557, 178, 952, 218,
                634, 785, 251, 290, 156, 300, 711, 322, 570, 820, 191, 755, 429, 950, 18, 917, 905, 905, 126, 790,
                638, 94, 857, 235, 889, 611, 605, 203, 859, 749, 874, 530, 727, 764, 197, 537, 951, 919, 24, 341,
                334, 505, 796, 619, 492, 295, 380, 128, 533, 600, 160, 51, 249, 5, 837, 905, 747, 505, 82, 158, 687,
                507, 339, 575, 206, 28, 29, 91, 459, 118, 284, 995, 544, 3, 154, 89, 840, 364, 682, 700, 143, 173,
                216, 290, 733, 525, 399, 574, 693, 500, 189, 590, 529, 972, 378, 299, 461, 866, 326, 43, 711, 460,
                426, 947, 391, 536, 26, 579, 304, 852, 158, 621, 683, 901, 237, 22, 225, 59, 52, 798, 262, 754, 649,
                504, 861, 472, 480, 570, 347, 891, 956, 347, 31, 784, 581, 668, 127, 628, 962, 698, 191, 313, 714,
                893
            }
                                                                , 101));
        }
Exemplo n.º 3
0
        public void TextJustification_Solutions(string[] words, int maxWidth, string[] expected)
        {
            var solution = new TextJustificationClass();
            var result   = solution.TextJustification(words, maxWidth);

            AssertEnumerable.AreEqual(expected, result);
        }
Exemplo n.º 4
0
        public void ReverseWords_Solutions()
        {
            var str = new[] { 't', 'h', 'e', ' ', 's', 'k', 'y', ' ', 'i', 's', ' ', 'b', 'l', 'u', 'e' };

            ReverseWords(str);
            AssertEnumerable.AreEqual(new[] { 'b', 'l', 'u', 'e', ' ', 'i', 's', ' ', 's', 'k', 'y', ' ', 't', 'h', 'e' },
                                      str);
        }
Exemplo n.º 5
0
        public void StrStrKMP_FailureFunction(string pattern, int[] expected)
        {
            var solution = new Solution();

            var result = solution.buildFailureFunction(pattern);

            AssertEnumerable.AreEqual(expected, result);
        }
Exemplo n.º 6
0
        public void CourseSchedule2_Solutions(int numCourses, string prerequisitesJson, int[] expected)
        {
            var prerequisites = JsonConvert.DeserializeObject <int[][]>(prerequisitesJson);
            var solution      = new CourseSchedule2();
            var result        = solution.FindOrder(numCourses, prerequisites);

            AssertEnumerable.AreEqual(expected, result);
        }
Exemplo n.º 7
0
        public void MaximumBinaryTree_Solutions()
        {
            int?[] expected = new int?[] { 6, 3, 5, null, 2, 0, null, null, 1 };

            TreeNode result = ConstructMaximumBinaryTree(new[] { 3, 2, 1, 6, 0, 5 });

            AssertEnumerable.AreEqual(expected, result.AsArray());
        }
Exemplo n.º 8
0
        public void GenerateParentheses_Solutions(int input, string expectedStr)
        {
            var expected = JsonConvert.DeserializeObject <List <string> >(expectedStr);
            var solution = new Solution();

            var result = solution.GenerateParenthesis(input);

            AssertEnumerable.AreEqual(expected, result);
        }
Exemplo n.º 9
0
 public void GFG_Solutions()
 {
     AssertEnumerable.AreEqual(new List <int> {
         787, 23
     }, kLargest(new List <int> {
         12, 5, 787, 1, 23
     }, 2));
     AssertEnumerable.AreEqual(new List <int> {
         50, 30, 23
     }, kLargest(new List <int> {
         1, 23, 12, 9, 30, 2, 50
     }, 3));
 }
Exemplo n.º 10
0
        public void BinarySearchTreeIterator_Solutions()
        {
            var root = TreeNode.GetTree(8, 3, 10, 1, 6, null, 14, null, null, 4, 7, null, null, 13, null);

            var i = new BSTIterator(root);

            var list = new List <int>();

            while (i.HasNext())
            {
                list.Add(i.Next());
            }

            AssertEnumerable.AreEqual(new[] { 1, 3, 4, 6, 7, 8, 10, 13, 14 }, list.ToArray());
        }
Exemplo n.º 11
0
 public void Waiter_Solutions()
 {
     AssertEnumerable.AreEqual(new[] { 4, 6, 3, 7, 5 }, waiter(new[] { 3, 4, 7, 6, 5 }, 1));
     AssertEnumerable.AreEqual(new[] { 4, 4, 9, 3, 3 }, waiter(new[] { 3, 3, 4, 4, 9 }, 2));
     AssertEnumerable.AreEqual(new[] { 4, 4, 9, 3, 3, 5 }, waiter(new[] { 3, 3, 4, 4, 9, 5 }, 3));
 }
 public void LetterCombinationsPhoneNumber_Solutions()
 {
     AssertEnumerable.AreEqual(new[] { "ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf" }, LetterCombinations("23"));
 }
Exemplo n.º 13
0
 public void NumberOfIslands2_Solutions()
 {
     AssertEnumerable.AreEqual(new[] { 1, 1, 2, 3 }, NumIslands2(3, 3, new[, ] {
         { 0, 0 }, { 0, 1 }, { 1, 2 }, { 2, 1 }
     }));
 }