public void TestFindLongestSubstringWithoutRepeatingCharacters(string searchString, int expectedAnswer)
        {
            var longestSubstringWithoutRepeatingCharactersSolver = new LongestSubstringWithoutRepeatingCharacters();
            var actualAnswer = longestSubstringWithoutRepeatingCharactersSolver.FindLongestSubstringWithoutRepeatingCharacters(searchString);

            Assert.AreEqual(expectedAnswer, actualAnswer);
        }
Example #2
0
        public void TestingLengthOfLongestSubstringWindow(string input, int expected)
        {
            var sub = new LongestSubstringWithoutRepeatingCharacters();

            var result = sub.LengthOfLongestSubstringWindow(input);

            Assert.AreEqual(expected, result);
        }
Example #3
0
        public void Test4()
        {
            var input = "abba";

            var result = new LongestSubstringWithoutRepeatingCharacters().LengthOfLongestSubstring(input);

            Assert.AreEqual(2, result);
        }
Example #4
0
        public void LengthOfLongestSubstringTest()
        {
            var solution = new LongestSubstringWithoutRepeatingCharacters();

            Assert.AreEqual(3, solution.LengthOfLongestSubstring("abcabcbb"));
            Assert.AreEqual(1, solution.LengthOfLongestSubstring("bbbbb"));
            Assert.AreEqual(3, solution.LengthOfLongestSubstring("pwwkew"));
            Assert.AreEqual(3, solution.LengthOfLongestSubstring("dvdf"));
            Assert.AreEqual(0, solution.LengthOfLongestSubstring(""));
        }
Example #5
0
        public void LongestSubstringWithoutRepeatingCharacters(string str, int result)
        {
            //Given
            var longestSubstringWithoutRepeatingCharacters = new LongestSubstringWithoutRepeatingCharacters();

            //When
            var value = longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstringSlidingWindowOptimizedASCII(str);

            //Then
            value.Should().Be(result);
        }
Example #6
0
        public void TestMethod1(string s, int expected)
        {
            // Arrange
            LongestSubstringWithoutRepeatingCharacters question = new LongestSubstringWithoutRepeatingCharacters();

            // Act
            int actual = question.LengthOfLongestSubstring(s);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void LongestSubstringWithoutRepeatingCharactersTestMethod()
        {
            LongestSubstringWithoutRepeatingCharacters longestSubstringWithoutRepeatingCharacters = new LongestSubstringWithoutRepeatingCharacters();

            Assert.AreEqual(3, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("abcabcbb"));
            Assert.AreEqual(2, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("abba"));
            Assert.AreEqual(1, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("bbbb"));
            Assert.AreEqual(3, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("pwwkew"));
            Assert.AreEqual(2, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("au"));
            Assert.AreEqual(1, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("a"));
            Assert.AreEqual(7, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("bpfbhmipx"));
            Assert.AreEqual(6, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("ggububgvfk"));
            Assert.AreEqual(3, longestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring("pwwkew"));
        }
        public void LengthOfLongestSubstringTests()
        {
            LongestSubstringWithoutRepeatingCharacters obj = new LongestSubstringWithoutRepeatingCharacters();


            //var x =  obj.LengthOfLongestSubstring("abba");//2

            var x = obj.LengthOfLongestSubstring("abcabcbb"); //3

            x = obj.LengthOfLongestSubstring("bbbbb");        //1
            x = obj.LengthOfLongestSubstring("pwwkew");       //3

            x = obj.LengthOfLongestSubstring(" ");            //1

            x = obj.LengthOfLongestSubstring("aab");          //2
            x = obj.LengthOfLongestSubstring("abba");         //2
            x = obj.LengthOfLongestSubstring("tmmzuxt");      //5
        }
Example #9
0
        public int LongestSubstringWithoutRepeatingCharacters(string s)
        {
            var solver = new LongestSubstringWithoutRepeatingCharacters();

            return(solver.Solution(s));
        }
Example #10
0
        public void TestCase7()
        {
            var input = "au";

            LongestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring(input).Should().Be(2);
        }
Example #11
0
        public void TestCase3()
        {
            var input = "pwwkew";

            LongestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring(input).Should().Be(3);
        }
Example #12
0
        static void Main(string[] args)
        {
            #region 1. Two Sum

            TwoSums twoSums = new TwoSums(new int[] { 2, 7, 11, 15 }, 18);
            twoSums.PrintExample();

            #endregion

            #region 3. LongestSubstringWithoutRepeatingCharacters

            LongestSubstringWithoutRepeatingCharacters longestSubstringWithoutRepeating = new LongestSubstringWithoutRepeatingCharacters("abcdecb");
            longestSubstringWithoutRepeating.PrintExample();

            #endregion

            #region 7. Reverse Integer

            ReverseInteger reverseInteger = new ReverseInteger(-54321);
            reverseInteger.PrintExample();

            #endregion

            #region 8. String to Integer (atoi)

            StringToInteger stringToInteger = new StringToInteger("  -42");
            stringToInteger.PrintExample();

            #endregion

            #region 9. Palindrome Number

            PalindromeNumber palindromeNumber = new PalindromeNumber(121);
            palindromeNumber.PrintExample();

            #endregion

            #region 20. Valid Parentheses

            ValidParentheses validParentheses = new ValidParentheses("(){[]}");
            validParentheses.PrintExample();

            #endregion

            #region 26. Remove Duplicates from Sorted Array

            RemoveDuplicatesFromSortedArray removeDuplicatesFromSortedArray = new RemoveDuplicatesFromSortedArray(new [] { 1, 2, 3, 3, 4, 5, 5, 5, 5, 5, 5, 6 });
            removeDuplicatesFromSortedArray.PrintExample();

            #endregion

            #region 35. Search Insert Position

            SearchInsertPosition searchInsertPosition = new SearchInsertPosition(new [] { 1, 3, 5, 10 }, 9);
            searchInsertPosition.PrintExample();

            #endregion

            #region 58. Length of Last Word

            LengthOfLastWord lengthOfLastWord = new LengthOfLastWord("Hello World");
            lengthOfLastWord.PrintExample();

            #endregion

            #region 104. Maximum Depth of Binary Tree



            #endregion

            #region 125. Valid Palindrome

            ValidPalindrome validPalindrome = new ValidPalindrome("A man, a plan, a canal: Panama");
            validPalindrome.PrintExample();

            #endregion

            #region 136. Single Number

            SingleNumber singleNumber = new SingleNumber(new [] { 2, 2, 3, 3, 1 });
            singleNumber.PrintExample();

            #endregion

            #region 150. Evaluate Reverse Polish Notation

            EvaluateReversePolishNotation evaluateReversePolishNotation = new EvaluateReversePolishNotation(new [] { "2", "1", "+", "3", "*" });
            evaluateReversePolishNotation.PrintExample();

            #endregion

            #region 155. Min Stack

            MinStack minStack = new MinStack();
            minStack.PrintExample();

            #endregion

            #region 167. Two Sum II - Input array is sorted

            TwoSumII twoSumII = new TwoSumII(new [] { 1, 2, 3, 7 }, 10);
            twoSumII.PrintExample();

            #endregion

            #region 200. Number of Islands

            NumberOfIslands numberOfIslands = new NumberOfIslands(new char[, ]
            {
                { '1', '1', '0', '0', '0' },
                { '1', '1', '0', '0', '0' },
                { '0', '0', '1', '0', '0' },
                { '0', '0', '0', '1', '1' }
            });
            numberOfIslands.PrintExample();

            #endregion

            #region 217. Contains Duplicate

            ContainsDuplicate containsDuplicate = new ContainsDuplicate(new [] { 1, 2, 3, 1 });
            containsDuplicate.PrintExample();

            #endregion

            #region 268. Missing Number

            MissingNumber missingNumber = new MissingNumber(new [] { 9, 6, 4, 2, 3, 5, 7, 0, 1 });
            missingNumber.PrintExample();

            #endregion

            #region 344. Reverse String

            ReverseString reverseString = new ReverseString("A man with a plan");
            reverseString.PrintExample();

            #endregion

            #region 387. First Unique Character in a String

            FirstUniqueCharacterInAString firstUniqueChar = new FirstUniqueCharacterInAString("loveleetcode");
            firstUniqueChar.PrintExample();

            #endregion

            #region 412. FizzBuzz

            FizzBuzz fizzBuzz = new FizzBuzz(15);
            fizzBuzz.PrintExample();

            #endregion

            #region 485. Max Consecutive Ones

            MaxConsecutiveOnes maxConsecutiveOnes = new MaxConsecutiveOnes(new int[] { 1, 1, 0, 1, 1, 1 });
            maxConsecutiveOnes.PrintExample();

            #endregion

            #region 509. Fibonacci Number

            FibonacciNumber fibonacciNumber = new FibonacciNumber(10);
            fibonacciNumber.PrintExample();

            #endregion

            #region 622. Design Circular Queue

            CircularQueue circularQueue = new CircularQueue(1);
            Console.WriteLine("622. Design Circular Queue");
            Console.WriteLine($"Front()   : {circularQueue.Front()}");
            Console.WriteLine($"IsEmpty() : {circularQueue.IsEmpty()}");
            circularQueue.EnQueue(1);
            Console.WriteLine($"EnQueue(1)");
            Console.WriteLine($"IsEmpty() : {circularQueue.IsEmpty()}");
            Console.WriteLine($"IsFull()  : {circularQueue.IsFull()}\n");

            #endregion

            #region 707. Design Linked List

            LinkedList linkedList = new LinkedList(new Node());
            linkedList.AddAtTail(10);
            linkedList.AddAtTail(20);
            linkedList.PrintLinkedList();

            #endregion

            #region 709. To Lower Case

            ToLowerCase toLowerCase = new ToLowerCase("LOVELY");
            toLowerCase.PrintExample();

            #endregion

            #region 739. Daily Temperatures

            DailyTemperatures dailyTemperatures = new DailyTemperatures(new [] { 89, 62, 70, 58, 47, 47, 46, 76, 100, 70 });
            dailyTemperatures.PrintExample();

            #endregion

            #region 747. Largest Number at Least Twice of Others

            LargestNumberAtLeastTwiceOfOthers largestNumberAtLeastTwiceOfOthers = new LargestNumberAtLeastTwiceOfOthers(new [] { 3, 6, 1, 0 });
            largestNumberAtLeastTwiceOfOthers.PrintExample();

            #endregion

            #region 771. Jewels and Stones
            string          j = "aA", s = "aAAbbbb";
            JewelsAndStones jewelsAndStones = new JewelsAndStones(j, s);
            jewelsAndStones.PrintExample();

            #endregion

            #region 832. Flipping an Image
            int[][] flippingImageArray      = new int[3][];
            flippingImageArray[0] = new int[] { 1, 1, 0 };
            flippingImageArray[1] = new int[] { 1, 0, 1 };
            flippingImageArray[2] = new int[] { 0, 0, 0 };
            FlippingAnImage flippingAnImage = new FlippingAnImage(flippingImageArray);
            flippingAnImage.PrintExample();

            #endregion

            #region 917. Reverse Only Letters

            ReverseOnlyLetters reverseOnlyLetters = new ReverseOnlyLetters("Qedo1ct-eeLg=ntse-T!");
            reverseOnlyLetters.PrintExample();

            #endregion


            Console.ReadLine();
        }
Example #13
0
 public void LongestSubstringWithoutRepeatingCharactersTest()
 {
     Assert.Throws <ArgumentNullException>(() => LongestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring(null));
 }
Example #14
0
 public int LongestSubstringWithoutRepeatingCharactersTest(string s)
 {
     return(LongestSubstringWithoutRepeatingCharacters.LengthOfLongestSubstring(s));
 }
 public int TestSolution(string s)
 {
     return(LongestSubstringWithoutRepeatingCharacters.Solution(s));
 }