public void RemoveDuplicatesTest() { int[] test = { 1, 1, 2 }; RemoveDuplicatesFromSortedArray ss = new RemoveDuplicatesFromSortedArray(); Assert.AreEqual(ss.RemoveDuplicates(test), 3); }
public void removeDuplicates2Test() { int[] test = { 1, 1, 2 }; RemoveDuplicatesFromSortedArray ss = new RemoveDuplicatesFromSortedArray(); Assert.AreEqual(ss.removeDuplicates2(test), 2); }
public void RemoveDuplicatesFromSortedArrayTestCase1() { var testData = new[] { 1, 1, 2 }; var result = RemoveDuplicatesFromSortedArray.RemoveDuplicates(testData); result.Should().Be(2); testData.Should().StartWith(new[] { 1, 2 }); }
public void RemoveDuplicatesFromSortedArrayTestCase2() { var testData = new[] { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4 }; var result = RemoveDuplicatesFromSortedArray.RemoveDuplicates(testData); result.Should().Be(5); testData.Should().StartWith(new[] { 0, 1, 2, 3, 4 }); }
public void RemoveDuplicatesTest(int[] input, int[] expected) { var t = new RemoveDuplicatesFromSortedArray(); var actual = t.RemoveDuplicates(input); Assert.True(actual == expected.Length); input.Take(actual).Should().BeEquivalentTo(expected); }
public void When10Elements_Returns5() { var sut = new RemoveDuplicatesFromSortedArray(); var nums = new int[] { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4 }; var result = sut.RemoveDuplicates(nums); ShowArray(nums); Assert.That(result, Is.EqualTo(5)); }
public void Test(int[] input, int[] result) { int count = RemoveDuplicatesFromSortedArray.RemoveDuplicates(input); Assert.Equal(result.Length, count); for (int i = 0; i < count; ++i) { Assert.Equal(input[i], result[i]); } }
public void Test1() { var array = new[] { 1, 2, 2 }; var resultArrayLength = new RemoveDuplicatesFromSortedArray().RemoveDuplicates(array); Assert.That(resultArrayLength, Is.EqualTo(2)); Assert.That(array[0], Is.EqualTo(1)); Assert.That(array[1], Is.EqualTo(2)); }
public void When122_Returns2() { var sut = new RemoveDuplicatesFromSortedArray(); var nums = new int[] { 1, 2, 2 }; var result = sut.RemoveDuplicates(nums); ShowArray(nums); Assert.That(result, Is.EqualTo(2)); Assert.That(nums[1], Is.EqualTo(2)); }
public void When0_Returns0() { var sut = new RemoveDuplicatesFromSortedArray(); var nums = new int[0] { }; var result = sut.RemoveDuplicates(nums); ShowArray(nums); Assert.That(result, Is.EqualTo(0)); }
public void RemoveDuplicatesFromSortedArrayShouldCorrectlyRemoveDuplicatesAndReturnNewLength_Testcase_3() { // Arrange var sortedArray = new int[] { 5, 5, 6, 6, 7, 7, 8, 8, 9 }; // Act var sortedArrayWithoutDuplicatesLength = RemoveDuplicatesFromSortedArray.GetLengthWithoutDuplicates(sortedArray); // Assert Assert.AreEqual(5, sortedArrayWithoutDuplicatesLength); }
public void RemoveDuplicatesFromSortedArrayShouldCorrectlyRemoveDuplicatesAndReturnNewLength_Testcase_2() { // Arrange var sortedArray = new int[] { 2, 2, 3, 3, 4, 7, 8, 9, 9, 18, 18, 26, 29, 29 }; // Act var sortedArrayWithoutDuplicatesLength = RemoveDuplicatesFromSortedArray.GetLengthWithoutDuplicates(sortedArray); // Assert Assert.AreEqual(9, sortedArrayWithoutDuplicatesLength); }
public void RemoveDuplicatesFromSortedArrayShouldCorrectlyRemoveDuplicatesAndReturnNewLength_Testcase_1() { // Arrange var sortedArray = new int[] { 1, 3, 3, 5, 7, 8, 10, 11, 11, 14, 16, 16 }; // Act int sortedArrayWithoutDuplicatesLength = RemoveDuplicatesFromSortedArray.GetLengthWithoutDuplicates(sortedArray); // Assert Assert.AreEqual(9, sortedArrayWithoutDuplicatesLength); }
public void TestRemoveDuplicates2() { int[] nums = new int[] { 0, 0, 1, 1, 1, 1, 2, 3, 3 }; int[] excepted = new int[] { 0, 0, 1, 1, 2, 3, 3 }; //act RemoveDuplicatesFromSortedArray mz = new RemoveDuplicatesFromSortedArray(); mz.RemoveDuplicates2(nums); // Assert.Equal(excepted, nums); }
public void RemoveDuplicatesTest_empty() { // Arrange RemoveDuplicatesFromSortedArray algo = new RemoveDuplicatesFromSortedArray(); int[] nums = { }; // Act int length = algo.RemoveDuplicates(nums); // Assert Assert.AreEqual(length, 0); }
public void Given_array_When_remove_duplicate_Then_return() { var array = new int[] { 1, 1, 2 }; var expect = new int[] { 1, 2, 0 }; var count = RemoveDuplicatesFromSortedArray.RemoveDuplicates(array); Assert.AreEqual(2, count); for (int i = 0; i < 2; i++) { Assert.AreEqual(expect[i], array[i]); } }
public void RemoveDuplicatesTest(int[] nums, int expectedLength, int[] expectedSet) { var sln = new RemoveDuplicatesFromSortedArray(); var actualLength = sln.RemoveDuplicates(nums); Assert.Equal(expectedLength, actualLength); if (nums != null) { for (int i = 0; i < expectedSet.Length; i++) { Assert.Equal(expectedSet[i], nums[i]); } } }
public void RemoveDuplicatesTest_122() { // Arrange RemoveDuplicatesFromSortedArray algo = new RemoveDuplicatesFromSortedArray(); int[] nums = { 1, 2, 2 }; // Act int length = algo.RemoveDuplicates(nums); // Assert Assert.AreEqual(length, 2); Assert.AreEqual(nums[0], 1); Assert.AreEqual(nums[1], 2); }
public void RemoveDuplicatesTest_000123() { // Arrange RemoveDuplicatesFromSortedArray algo = new RemoveDuplicatesFromSortedArray(); int[] nums = { 0, 0, 0, 1, 2, 3 }; // Act int length = algo.RemoveDuplicates(nums); // Assert Assert.AreEqual(length, 4); for (int i = 0; i < length; i++) { Assert.AreEqual(nums[i], i); } }
public void RemoveDuplicatesTests() { RemoveDuplicatesFromSortedArray obj = new RemoveDuplicatesFromSortedArray(); var nums = new int[] { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4 }; int len = obj.RemoveDuplicates(nums); nums = new int[] { 0, 0, 1, 1, 1, 2, 2, 3, 3, 3 }; len = obj.RemoveDuplicates(nums); nums = new int[] { 0 }; len = obj.RemoveDuplicates(nums); nums = new int[] { 0, 0 }; len = obj.RemoveDuplicates(nums); nums = new int[] { }; len = obj.RemoveDuplicates(nums); nums = new int[] { 1, 1, 2 }; len = obj.RemoveDuplicates(nums); }
public RemoveDuplicatesFromSortedArrayTests() { _objUnderTest = new RemoveDuplicatesFromSortedArray(); }
public static void TestingLengthArrays(int expectedarraylength, int[] givenarray) { int actualarraylength = RemoveDuplicatesFromSortedArray.RemoveDuplicates(new int[] { 1, 1, 2 }); Assert.AreEqual(expectedarraylength, actualarraylength); }
public void BeforeEach() { removeDuplicatesFromSortedArray = new RemoveDuplicatesFromSortedArray(); }
static void Main(string[] args) { SortedMatrixSearch.Run(); SparseSearch.Run(); SearchInRotatedArray.Run(); GroupAnagrams.Run(); CombinationsOfNPairsParentheses.Run(); PermutationWithDuplicates.Run(); PermutationNoDuplicates.Run(); var subsetList = new List <List <int> >(); subsetList = SubsetInSet.FindAllSubsetInSet(new List <int> { 1, 2, 3 }); ReverseLinkedList.Run(); IsUniqueString.Run(); StoneDivisionProblem.Run(); Kangaroo.Run(); AppleAndOrange.Run(); AbbreviationProblem.Run(); FibonacciModifiedProblem.Run(); RecursiveDigitSum.Run(); RangeSumOfBST.Run(); GradingStudentsProblem.Run(); // XorSequenceProblem.Run(); CounterGameProblem.Run(); MaximizingXORProblem.Run(); LonelyIntegerProblem.Run(); FlippingBitsProblem.Run(); QueueUsingTwoStacksProblem.Run(); GetNodeValue.Run(); MergeTwoSortedLinkedLists.Run(); Compare_Two_linked_lists.Run(); DeleteNodeProblem.Run(); ArrayManipulationProblem.Run(); LeftRotationProblem.Run(); HourGlass2D.Run(); SimpleTextEditorProblem.Run(); EqualStacksProblem.Run(); MaximumElementProblem.Run(); BinarySearchTreeInsertion.Run(); TopViewProblem.Run(); TimeConvertsionProblem.Run(); BinaryTreePathsProblem.Run(); IncreasingOrderSearchTree.Run(); RemoveAllAdjacentDuplicatesInStringWithKLength.Run(); RemoveAllAdjacentDuplicatesInString.Run(); CheckStraightLineProblem.Run(); HouseRobber.Run(); UniquePathsProblem.Run(); FirstUniqueCharacterInString.Run(); BinaryTreeInorderTraversal.Run(); DailyTemperaturesProblem.Run(); CountingBitsproblem.Run(); SortIntegersByTheNumberOf1BitsProblem.Run(); HammingDistanceProblem.Run(); RansomNoteProblem.Run(); ConvertBinaryNumberInLinkedListToIntegerProblem.Run(); NumberOfStepsToReduceNumberToZeroProblem.Run(); JewelsAndStones.Run(); ClimbingStairsProblem.Run(); BestTimeToBuyAndSellStock.Run(); MajorityElementProblem.Run(); MoveZeroesProblem.Run(); InvertBinaryTree.Run(); SingleNumberProblem.Run(); MaximumDepthInTrree.Run(); MergeTwoBinaryTrees.Run(); AddBinaryProblem.Run(); PlusOneProblem.Run(); LengthOfLastWordProblem.Run(); KadaneAlgorithmForMaxSubArray.Run(); KMPAlgorithm.Run(); CountAndSayProblem.Run(); SearchInsertPosition.Run(); ImplementIndexOfString.Run(); RemoveElement.Run(); RemoveDuplicatesFromSortedArray.Run(); MergeTwoSortedLists.Run(); ValidParentheses.Run(); LongestCommonPrefix.Run(); RomanToInteger.Run(); PalindromeNumber.Run(); ReverseInteger.Run(); TwoSumProblem.Run(); AddOneToNumber.Run(); MostAmountOfChange.Run(); #region BinaryTree LeastCommonAncestor.Run(); PrintAllPaths.Run(); HasPathSum.Run(); CheckIfBinaryTreeIsBinarySearchTree.Run(); PrintAllNodesWithRangeInBinarySearchTree.Run(); UniqueTreeStructureNumber.Run(); MirrorTree.Run(); #region BitManuiplation_GetNthNumber NumberOfStepsToReduceNumberToZeroProblem.Run(); CountNumbersOf1InBit.Run(); ReverseThebitsInInteger.Run(); PrintBitsInInteger.Run(); GetNthBit.Run(); setNthBitTo1.Run(); SetNthBitTo0.Run(); #endregion MinimumtValueInTrree minValueInTree = new MinimumtValueInTrree(); minValueInTree.Run(); #endregion #region Recursion Chessboard chessboard = new Chessboard(); chessboard.Run(); RatPathToMaze ratPathToMaze = new RatPathToMaze(); ratPathToMaze.Run(); List <string> anagramList = new List <string>(); anagramList = WordAnagram.GenerateWordAnagram("abc"); Pixel[,] pixelList = new Pixel[3, 3] { { new Pixel(0, 0, "red"), new Pixel(0, 1, "green"), new Pixel(0, 2, "green") }, { new Pixel(1, 0, "red"), new Pixel(1, 1, "green"), new Pixel(1, 2, "green") }, { new Pixel(2, 0, "red"), new Pixel(2, 1, "green"), new Pixel(2, 2, "green") } }; FillPaint.PaintFill(pixelList, 1, 2, "green", "black"); BinaryTreesAreTheSame.Run(); #endregion #region General problems RotateArrayByKSpaces.Run(); #region AddtwoNumbersReferencedByTheirDigits var addRes = AddtwoNumbersReferencedByTheirDigits.AddNumbers(new int[] { 1, 2, 7 }, new int[] { 9, 4 }); #endregion #region RunLengthEncoding var encodedStr = RunLengthEncoding.Encode("aabbbbc"); var decodedStr = RunLengthEncoding.Decode(encodedStr); #endregion #region BreakDocumentIntoChunk var chunkRes = BreakDocumentIntoChunk.Chunkify("ab:dd:ddfcct:aab:cccc", ':', 5); #endregion #region GameOfLife var gameRes = GameOfLife.GetNextInteration(new int[3, 3] { { 1, 0, 0 }, { 0, 1, 1 }, { 1, 0, 0 } }); #endregion . #endregion #region InsertionSort InsertionSort.insertionSort(listToSort); #endregion #region BinarySearch Console.WriteLine(String.Format("%s is present at index: %s", 30, BinarySearch.binarySearch(sortedArray, 30, 0, sortedArray.Length - 1))); Console.WriteLine(String.Format("%s is present at index: %s", 4, BinarySearch.binarySearch(sortedArray, 4, 0, sortedArray.Length - 1))); Console.WriteLine(String.Format("%s is present at index: %s", 15, BinarySearch.binarySearch(sortedArray, 15, 0, sortedArray.Length - 1))); #endregion #region MergeSort MergeSort.print(listToSort); MergeSort.mergeSort(listToSort); #endregion #region QuickSort QuickSort.print(listToSort); QuickSort.quickSort(listToSort, 0, listToSort.Length - 1); QuickSort.print(listToSort); #endregion }
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(); }