Beispiel #1
0
        public void FourSumWithTwoPointersWithIncrementAndDecrement_Success()
        {
            var expectedResult = new List <List <int> >()
            {
                new List <int>()
                {
                    -1, 0, 0, 1
                },
                new List <int>()
                {
                    -2, -1, 1, 2
                },
                new List <int>()
                {
                    -2, 0, 0, 2
                }
            };

            int[] nums = new int[] { 1, 0, -1, 0, -2, 2 };

            var result = new KSum().FourSumWithTwoPointersWithIncrementAndDecrement(nums);

            var areEqual = CollectionsAreEqual.AreEqualListOfLists(result, expectedResult);

            Assert.IsTrue(areEqual);
        }
Beispiel #2
0
        public void TwoSumWithHashMap_Success()
        {
            int[] nums           = new int[] { 2, 7, 11, 15 };
            var   expectedResult = new List <List <int> >()
            {
                new List <int>()
                {
                    0, 1
                },
            };
            var result = new KSum().TwoSumWithHashMap(nums, 9);

            var areEqual = CollectionsAreEqual.AreEqualListOfLists(result, expectedResult);

            Assert.IsTrue(areEqual);
        }
Beispiel #3
0
        public void ThreeSumWithTwoPointers_Success()
        {
            var expectedResult = new List <List <int> >()
            {
                new List <int>()
                {
                    -1, 0, 1
                },
                new List <int>()
                {
                    -1, -1, 2
                }
            };

            int[] nums = new int[] { -1, 0, 1, 2, -1, -4 };

            var result = new KSum().ThreeSumWithTwoPointers(nums);

            var areEqual = CollectionsAreEqual.AreEqualListOfLists(result, expectedResult);

            Assert.IsTrue(areEqual);
        }
Beispiel #4
0
        public void NaiveSolution_Success()
        {
            var expectedResult = new List <List <int> >()
            {
                new List <int>()
                {
                    0, 1
                },
                new List <int>()
                {
                    1, 0
                }
            };

            List <string> words = new List <string>()
            {
                "bat", "tab", "cat"
            };
            var result = new PalindromePair().BruteForceSolution(words);

            var areEqual = CollectionsAreEqual.AreEqualListOfLists(result, expectedResult);

            Assert.IsTrue(areEqual);
        }