public void ContainDuplicate() { int[] nums = { 1, 1, 2, 3, 4, 5 }; bool flag = ContainsDuplicate.ContainDuplicate(nums); Assert.AreEqual(true, flag); }
public void ContainsDuplicateSolutionTest() { int[] testArray = new int[] { 1, 3, 4, 6, 7, 2, 1, 5 }; ContainsDuplicate myCD = new ContainsDuplicate(); myCD.ContainsDuplicateSolution(testArray); Assert.Fail(); }
static void Main(string[] args) { NumberOfIslands number = new NumberOfIslands(); Console.WriteLine(number.IslandCount()); SpiralPrint sp = new SpiralPrint(); sp.Print(); PascalTriangle pt = new PascalTriangle(); pt.Generate(6); pt.Print(); MedianOfSortedArrays ms = new MedianOfSortedArrays(); Console.WriteLine(ms.MedianOf2SortedArrays(ms.array1, ms.array2)); FindtheMissingNumber fn = new FindtheMissingNumber(); Console.WriteLine(fn.FindtheMissingNumberMethod1()); ContainsDuplicate cd = new ContainsDuplicate(); Console.WriteLine(cd.isDuplicateMethod2()); ReversedLinkedList rl = new ReversedLinkedList(); rl.reversedList(); ReverseNumber rn = new ReverseNumber(); rn.ReverseANumber(12345); LinearSearch ls = new LinearSearch(); BinarySearch bs = new BinarySearch(); ZigZag zz = new ZigZag(); Console.WriteLine(zz.Convert("PAYPALISHIRING", 3)); BinaryTree bt = new BinaryTree(); bt.InorderTraverse(bt.root); Console.WriteLine(); bt.PreorderTraverse(bt.root); Console.WriteLine(); bt.PostorderTraverse(bt.root); RotateArray ra = new RotateArray(3); //SearchRotatedArray sr = new SearchRotatedArray(3); //Console.WriteLine(sr.Find()); FindSumSarray fS = new FindSumSarray(); MaxSumSubArray mxSum = new MaxSumSubArray(); }
public void ExecuteTest2() { var inputs = new[] { new[] { 1, 2, 3, 1 }, new[] { 1, 2, 3, 4 }, new[] { 1, 1, 1, 3, 3, 4, 3, 2, 4, 2 } }; var expecteds = new[] { true, false, true }; foreach (var(input, expected) in inputs.Zip(expecteds)) { ContainsDuplicate.Execute2(input).Should().Be(expected); } }
private static void ContainsDuplicate() { var inputArray = new[] { -1, -2, 10, 8, 1, -20, 20, 1, 2, -10, -15 }; var containDuplicateSolution0Result = new ContainsDuplicate(inputArray).ContainDuplicateSolution0Result(); var containDuplicateSolution1Result = new ContainsDuplicate(inputArray).ContainsDuplicateSolution1Result(); var containsDuplicateSolution2Result = new ContainsDuplicate(inputArray).ContainsDuplicateSolution2Result(); var containsDuplicateSolution3Result = new ContainsDuplicate(inputArray).ContainsDuplicateSolution3Result(); Console.WriteLine("Contains Duplicate:"); Console.WriteLine($"Input Array :{string.Join(',', inputArray)}"); Console.WriteLine($"ContainDuplicateSolution0Result :- {containDuplicateSolution0Result}"); Console.WriteLine($"ContainDuplicateSolution1Result :- {containDuplicateSolution1Result}"); Console.WriteLine($"ContainsDuplicateSolution2Result :- {containsDuplicateSolution2Result}"); Console.WriteLine($"ContainsDuplicateSolution3Result :- {containsDuplicateSolution3Result}"); }
void InternalTest(int[] nums, bool expected) { bool actual = ContainsDuplicate.Solve(nums); Assert.Equal <bool>(expected, actual); }
public void TestSolution(int[] input1, bool expectedResult) { var result = new ContainsDuplicate().Resolve(input1); Assert.AreEqual(expectedResult, result); }
private static void callContainsDuplicate() { ContainsDuplicate dups = new ContainsDuplicate(); Console.WriteLine(dups.hasDuplicate(new int[] { 1, 2, 3, 1 })); }
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(); }
static void Main(string[] args) { Console.WriteLine("Question 1"); int[] l1 = new int[] { 5, 6, 6, 9, 9, 12 }; int target = 9; int[] r = TargetRange.TargetRangeSoln(l1, target); // Write your code to print range r here Console.WriteLine("[" + r[0] + "," + r[1] + "]"); Console.WriteLine("Question 2"); String s = "University of South Florida"; String rs = StringReverse.StringReverseSoln(s); Console.WriteLine(rs); Console.WriteLine("Question 3"); int[] l2 = new int[] { 2, 2, 3, 5, 6 }; int sum = MinimumSum.MinimumSumSoln(l2); Console.WriteLine(sum); Console.WriteLine("Question 4"); string s2 = "Dell"; string sortedString = FreqSort.FreqSortSoln(s2); Console.WriteLine(sortedString); Console.WriteLine("Question 5-Part 1"); int[] nums1 = { 1, 1, 2, 2, 2 }; int[] nums2 = { 2, 2 }; //int[] nums1 = { 3, 6, 6, 3}; //int[] nums2 = { 6, 3, 6, 7, 3 }; int[] intersect1 = Intersect.Intersect1(nums1, nums2); Console.WriteLine("Part 1- Intersection of two arrays is: "); Intersect.DisplayArray(intersect1); Console.WriteLine("\n"); Console.WriteLine("Question 5-Part 2"); int[] intersect2 = Intersect.Intersect2(nums1, nums2); Console.WriteLine("Part 2- Intersection of two arrays is: "); Intersect.DisplayArray(intersect2); Console.WriteLine("\n"); Console.WriteLine("Question 6"); char[] arr = new char[] { 'a', 'g', 'h', 'a' }; int k = 3; Console.WriteLine(ContainsDuplicate.ContainsDuplicateSoln(arr, k)); Console.WriteLine("Question 7"); int rodLength = 4; int priceProduct = GoldRod.GoldRodSoln(rodLength); Console.WriteLine(priceProduct); Console.WriteLine("Question 8"); string[] userDict = new string[] { "rocky", "usf", "hello", "apple" }; string keyword = "hhllo"; Console.WriteLine(DictSearch.DictSearchSoln(userDict, keyword)); Console.WriteLine("Question 9"); SolvePuzzle.SolvePuzzleSoln(); }
static void Main(string[] args) { Console.WriteLine("Question 1"); int[] l1 = new int[] { 5, 6, 6, 9, 9, 12 }; int target = 9; int[] r = TargetRange.TargetRangeSoln(l1, target); // Write your code to print range r here Console.WriteLine("[" + r[0] + "," + r[1] + "]"); Console.WriteLine("Question 2"); String s = "University of South Florida"; String rs = StringReverse.StringReverseSoln(s); Console.WriteLine(rs); Console.WriteLine("Question 3"); int[] l2 = new int[] { 2, 2, 2, 4, 5, 7 }; int sum = MinimumSum.MinimumSumSoln(l2); Console.WriteLine("The Sum is: " + sum); Console.WriteLine("Question 4"); string s2 = "Dell"; string sortedString = FreqSort.FreqSortSoln(s2); Console.WriteLine(sortedString); Console.WriteLine("Question 5-Part 1"); int[] nums1 = { 1, 1, 2, 2, 2 }; int[] nums2 = { 2, 2 }; try { int[] intersect1 = Intersect.Intersect1(nums1, nums2); Console.WriteLine("Part 1- Intersection of two arrays is: "); Intersect.DisplayArray(intersect1); Console.WriteLine("\n"); Console.WriteLine("Question 5-Part 2"); int[] intersect2 = Intersect.Intersect2(nums1, nums2); Console.WriteLine("Part 2- Intersection of two arrays is: "); Intersect.DisplayArray(intersect2); Console.WriteLine("\n"); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Question 6"); char[] arr = new char[] { 'a', 'g', 'h', 'a' }; int k = 3; Console.WriteLine(ContainsDuplicate.ContainsDuplicateSoln(arr, k)); Console.WriteLine("Question 7"); int rodLength = 15; int priceProduct = GoldRod.GoldRodSoln(rodLength); Console.WriteLine(priceProduct); Console.WriteLine("Question 8"); string[] userDict = new string[] { "rocky", "usf", "hello", "apple" }; string keyword = "hhllo"; try { if (userDict.Length > 0) { Console.WriteLine(DictSearch.DictSearchSoln(userDict, keyword)); } else { Console.WriteLine("Enter an array with at least one element."); } } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Question 9"); Console.WriteLine(" "); try { SolvePuzzle.SolvePuzzleSoln(); }catch (Exception e) { Debug.WriteLine(e.StackTrace); Console.WriteLine("Error computing the solution."); } }
public void BeforeEach() { ContainsDuplicate = new ContainsDuplicate(); }