Example #1
0
 static void Main(string[] args)
 {
     var result1 = TwoSum1.TwoSum(new int[] { 2, 7, 11, 15 }, 9);
     var result2 = AddTwoNumbers2.AddTwoNumbers(
         new ListNode(2)
     {
         next = new ListNode(4)
         {
             next = new ListNode(3)
         }
     },
         new ListNode(5)
     {
         next = new ListNode(6)
         {
             next = new ListNode(4)
         }
     });
     var result3  = LongestSubstringWithoutRepeatingCharacters3.LengthOfLongestSubstring("abcabcbb");
     var result4  = MedianOfTwoSortedArrays4.FindMedianSortedArrays(new int[] { 1, 3 }, new int[] { 2 });
     var result5  = LongestPalindromicSubstring5.LongestPalindrome("aaabaaaa");
     var result6  = ZigZagConversion6.Convert("ABCD", 2);
     var result7  = ReverseInteger7.Reverse(-123);
     var result8  = StringToIntegerAtoi8.MyAtoi("4193 with words");
     var result9  = PalindromeNumber9.IsPalindrome(121);
     var result10 = RegularExpressionMatching10.IsMatch("ab", ".*..c*");
 }
        public void TwoSumWithSameKey()
        {
            var intArr = new int[4] {
                2, 2, 11, 15
            };
            var target = 9;
            var twoSum = new TwoSum1();
            var result = twoSum.TwoSum(intArr, target);

            Assert.IsNull(result);
        }
        public void TwoSumTest()
        {
            var intArr = new int[4] {
                2, 7, 11, 15
            };
            var target = 9;
            var twoSum = new TwoSum1();
            var result = twoSum.TwoSum(intArr, target);

            Assert.IsTrue(result.Contains(0));
            Assert.IsTrue(result.Contains(1));
            Assert.IsTrue(result.Aggregate((x, y) => intArr[x] + intArr[y]) == target);
        }
Example #4
0
        static void Main(string[] args)
        {
            string problem = string.Empty;

            do
            {
                Console.WriteLine("Enter Problem number: ");
                problem = Console.ReadLine();

                switch (problem)
                {
                case "merge-sort":
                {
                    var array = new int[] { 12, 233, 23, 343, 45, 52, 6, 81, 92, 8, 96, 34, 2, 3, 5, 28, 323 };
                    Console.WriteLine($"Merge Sort Result: {String.Join(",", MergeSortAlgorith.MergeSort(array))}");
                }
                break;

                case "1":
                {
                    var nums = new int[] { 2, 7, 11, 15 };
                    Console.WriteLine($"Input: {String.Join(",", nums)} - Result: {String.Join(",", TwoSum1.TwoSum(nums, 9))}");

                    var nums2 = new int[] { 3, 2, 4 };
                    Console.WriteLine($"Input: {String.Join(",", nums)} - Result: {String.Join(",", TwoSum1.TwoSum(nums2, 6))}");

                    var nums3 = new int[] { 3, 2, 3 };
                    Console.WriteLine($"Input: {String.Join(",", nums)} - Result: {String.Join(",", TwoSum1.TwoSum(nums3, 6))}");
                }
                break;

                case "242":
                {
                    Console.WriteLine($"Input: s = \"rat\", t = \"car\" - Result: {ValidAnagram242.IsAnagram("rat", "car")}");
                    Console.WriteLine($"Input: s = \"anagram\", t = \"nagaram\" - Result: {ValidAnagram242.IsAnagram("anagram", "nagaram")}");
                }
                break;

                case "x":
                    Console.WriteLine("Exiting...");
                    break;

                default:
                    Console.WriteLine("Invalid Problem Number!");
                    break;
                }
            } while (problem != "x");
        }