public void ReverseNegativeIntegerTest() { int startInt = -342; int reversedInt = LeetCode.ReverseInteger(startInt); Assert.AreEqual(-243, reversedInt); }
public void loadQuestions() { if (File.Exists(filePath)) { StreamReader questionRead = new StreamReader(filePath); while (!questionRead.EndOfStream) { LeetCode leetcode = new LeetCode(); string number = questionRead.ReadLine(); leetcode.Number = number; string name = questionRead.ReadLine(); leetcode.Name = name; string url = questionRead.ReadLine(); leetcode.Url = url; string checker = questionRead.ReadLine(); leetcode.Checker = checker; int index = int.Parse(questionRead.ReadLine()); leetcode.Index = index; leetCodeClass.Add(leetcode); leetCodeShow.Add(leetcode); } questionRead.Close(); } }
public void ReversePostitiveIntegerTest() { int startInt = 342; int reversedInt = LeetCode.ReverseInteger(startInt); Assert.AreEqual(243, reversedInt); }
public void CommonStringPrefixTest(string[] stringArray, string expectedCommonPrefix) { List <string> stringList = stringArray.ToList(); string testCommonPrefix = LeetCode.LongestCommonStringPrefix(stringList); Assert.AreEqual(expectedCommonPrefix, testCommonPrefix); }
private void EnterKeyPress() { for (int i = 0; i < leetCodeClass.Count; i++) { if (tbQuestionNumber.Text == leetCodeClass[i].Number) { DialogResult res = MessageBox.Show("This Question Number Is Already Added!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); tbQuestionNumber.Select(); return; } } if (tbQuestionNumber.TextLength == 0 || tbQuestionName.TextLength == 0 || tbLink.TextLength == 0) { DialogResult res = MessageBox.Show("You Need to Fill All Properties?", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); tbQuestionNumber.Select(); } else { LeetCode leetcode = new LeetCode(); leetcode.Number = tbQuestionNumber.Text; leetcode.Name = tbQuestionName.Text; leetcode.Url = tbLink.Text; if (cbSolved.Checked) { leetcode.Checker = "Yes"; } else { leetcode.Checker = "No"; } int indexes = leetCodeClass.Count; leetcode.Index = indexes; string leet = ""; if (!cbSolved.Checked) { leet = "No " + tbQuestionNumber.Text + " " + tbQuestionName.Text; lbQuestionBox.Items.Add(leet); } else { leet = "Yes " + tbQuestionNumber.Text + " " + tbQuestionName.Text; lbQuestionBox.Items.Add(leet); } tbQuestionName.Clear(); tbQuestionNumber.Clear(); tbQuestionNumber.Select(); tbLink.Clear(); cbSolved.Checked = false; leetCodeClass.Add(leetcode); WriteToFile(1); } }
void AssertRight(LeetCode.Code.ReverseNodesInKGroup.ListNode list, int[] array) { var currentNode = list; foreach (var item in array) { Assert.AreEqual(item, currentNode.val); currentNode = currentNode.next; } Assert.IsNull(currentNode); }
void AssertOrdered(LeetCode.Code.MergeKSortedLists.ListNode list, int count) { var nodeCount = 1; var currentListNode = list; while (currentListNode.next != null) { Assert.IsTrue(currentListNode.next.val >= currentListNode.val); currentListNode = currentListNode.next; nodeCount++; } Assert.AreEqual(count, nodeCount); }
static void Main(string[] args) { /////////////////////////Start Time Below////////////////////////////// LeetCode lc = new LeetCode(); DateTime start = DateTime.Now; /////////////////////////Functions Below/////////////////////////////// int[] test = { 2, 3, 4, 5, 6, 4, 3, 2, 5, 65, 67, 788, 5, 3, 2, 56, 2, 34, 34, 645, 7, 452, 3453, 564, 67, 425, 234, 5, 656, 86, 745, 63, 34, 43, 65, 45, 6, 2342, 123, 245, 467, 57, 45, 213, 1, 3456, 467, 68 }; Sort <int> .MergeSort(test); Print(test); /////////////////////////End Time Below//////////////////////////////// Console.WriteLine("time: " + (DateTime.Now - start).TotalSeconds); Console.ReadKey(); }
static void Main(string[] args) { BubbleSort bubbleSort = new BubbleSort(); //bubbleSort.StartUp(); SelectionSort selectionSort = new SelectionSort(); //selectionSort.StartUp(); InsertionSort insertionSort = new InsertionSort(); //insertionSort.StartUp(); LeetCode leetCode = new LeetCode(); //leetCode.RemoveDuplicates(new int[] {1,1,2,2,3,3 }); InfoSysInterviewQ1 infoSysInterviewQ1 = new InfoSysInterviewQ1(); //infoSysInterviewQ1.StartUp(); InfoSysInterviewQ2 infoSysInterviewQ2 = new InfoSysInterviewQ2(); // infoSysInterviewQ2.StartUp(); leetCode.MaxProfit(new int[] { 1, 2, 3, 4, 5 }); }
public void TwoSumTestWithValidInputs() { int[] integerArray = new int[] { 2, 7, 1, 15 }; int targetSum = 9; int[] indices = new int[2]; try { indices = LeetCode.TwoSum(integerArray, targetSum); } catch (ArgumentException) { Assert.Fail(); } Assert.AreEqual(integerArray[indices[0]] + integerArray[indices[1]], targetSum); }
public void TwoSumTestWithBadInputs() { int[] integerArray = new int[] { 2, 10, 1, 15 }; int targetSum = 9; int[] indices = new int[2]; bool caughtExceptionBool = false; try { indices = LeetCode.TwoSum(integerArray, targetSum); } catch (Exception) { caughtExceptionBool = true; } Assert.IsTrue(caughtExceptionBool); }
public void MergeListTests() { List <List <int> > listOfIntLists = new List <List <int> >(); listOfIntLists.Add(new List <int> { 0, 2, 4, 5, 6, 10, 11 }); listOfIntLists.Add(new List <int> { -1, 1, 4, 7, 3, 2, 1 }); listOfIntLists.Add(new List <int> { -10, 0, 15 }); List <int> sortedList = LeetCode.MergeLists(listOfIntLists); List <int> expectedSortedList = new List <int> { -10, -1, 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 7, 10, 11, 15 }; bool result = Enumerable.SequenceEqual(sortedList, expectedSortedList); Assert.IsTrue(result); }
void AssertRight(LeetCode.Code.SwapNodesInPairs.ListNode list, int[] array) { var currentNode = list; var index = 0; while (currentNode != null) { if (index % 2 == 0) if (index + 1 == array.Length) { Assert.AreEqual(array[index], currentNode.val); currentNode = currentNode.next; } else Assert.AreEqual(array[index], currentNode.next.val); else { Assert.AreEqual(array[index], currentNode.val); if (currentNode.next != null) currentNode = currentNode.next.next; } index++; } }
private static void Main(string[] args) { QuestionHelpers.Time(() => new Solution().UniquePaths(LeetCode.Int(), LeetCode.Int())); }
public void RectangleOverlap_ValidInput_False() { int[] rec1 = { 0, 0, 1, 1 }; int[] rec2 = { 1, 0, 2, 1 }; Assert.IsFalse(LeetCode.IsRectangleOverlap(rec1, rec2)); }
public void RectangleOverlap_ValidInput_True() { int[] rec1 = { 0, 0, 2, 2 }; int[] rec2 = { 1, 1, 3, 3 }; Assert.IsTrue(LeetCode.IsRectangleOverlap(rec1, rec2)); }
public void ReverseNegativeIntMinTest(int startInt) { int reversedInt = LeetCode.ReverseInteger(startInt); Assert.AreEqual(0, reversedInt); }
public void FizzBuzz_15_FizzBuzz() { var result = LeetCode.FizzBuzz(15); Assert.AreEqual(result[14].ToString(), "FizzBuzz"); }
public void IntIsPalindromTest(int startInt, bool expectedIsPalindrome) { bool testIsPalindrome = LeetCode.IntIsPalindrome(startInt); Assert.AreEqual(expectedIsPalindrome, testIsPalindrome); }
private static void Main(string[] args) { QuestionHelpers.Time(() => new Solution().MinPathSum(LeetCode.Grid())); }
public void MaxProfitTest_ShouldReturnExpectedOutcome(int[] prices, int output) { int actual = LeetCode.MaxProfit(prices); Assert.AreEqual(output, actual); }
private static void RandomExercises() { int[] numValues = { 8, 1, 2, 2, 3 }; ArrayExercises.SmallerNumbersThanCurrent(numValues); int[] FirstDuplicate = { 2, 1, 3, 5, 3, 2 }; Console.WriteLine(string.Format("{0} is the first duplicate.", ArrayExercises.FindFirstDuplicate(FirstDuplicate))); BinaryTree <int> MyTree = new BinaryTree <int>(); MyTree.Insert(6); MyTree.Insert(7); MyTree.Insert(8); MyTree.Insert(2); MyTree.Insert(7); MyTree.Insert(1); MyTree.Insert(3); MyTree.Insert(9); MyTree.Insert(1); MyTree.Insert(4); MyTree.Insert(5); MyTree.SumEvenGrandparent(MyTree.Find(6)); long binary_val = 100100111000000; BitManipulator x = new BitManipulator(); Console.WriteLine(x.GetDecimalValue(binary_val)); int[] luis = ManyExercises.BeautifulArray(4); int[] arri = { 1, 1, 2, 3, 3, 4, 4, 8, 8 }; int UniqueVal = ManyExercises.SingleNonDuplicate(arri); if (UniqueVal > -1) { Console.WriteLine(string.Format("Unique value is {0}.", UniqueVal)); } else { Console.WriteLine("No unique value is found in given array."); } Console.WriteLine("\n"); string a = "kqep"; string b = "pekeq"; CustomSortString.SortString(a, b); int[] Pancakes = { 3, 2, 4, 1 }; ArrayExercises.PancakeSort(Pancakes); // [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]] int[][] matrix = new int[5][] { new int[] { 11, 25, 66, 1, 69, 7 }, new int[] { 23, 55, 17, 45, 15, 52 }, new int[] { 75, 31, 36, 44, 58, 8 }, new int[] { 22, 27, 33, 25, 68, 4 }, new int[] { 84, 28, 14, 11, 5, 50 } }; Console.WriteLine("Original Matrix:"); PrintMatrix(matrix); JaggedArray.DiagonalSort(matrix); Console.WriteLine("\nDiagonally Sorted Matrix:"); PrintMatrix(matrix); Console.ReadLine(); int[] arr = { 8, 3, 2, 7, 9, 1, 4, 1 }; Console.WriteLine("\n"); Console.WriteLine("Before SelectionSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.ReadLine(); SelectionSortAlgorithm.SelectionSort(arr); Console.WriteLine("\n"); Console.WriteLine("After SelectionSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.WriteLine("\n"); Console.ReadLine(); Console.Write("Binary Search. Enter number to search for: "); int.TryParse(Console.ReadLine(), out int key); BinarySearchAlgorithm.BinarySearch(arr, key); arr = Sorting(); int[] G = { 1, 2, 3, 3, 4, 5 }; Console.WriteLine(OneDimensionalArray.FindDuplicate(G)); Console.ReadLine(); int[] arrX1 = { 3, 4, -7, 1, 3, 3, 1, -4 }; OneDimensionalArray.FindSubarrayForGivenSum(arrX1, 7); var y1 = new int[] { 3, 1, 7, 5, 4, 9, 2 }; InsertionSortAlgorithm.InsertionSortBitWise(y1); PrintResults(y1); //ArrayExercises.StoreElementsInArray(); var x1 = new int[] { 1, 2, 3 }; var x2 = new int[] { 1, 2, 3 }; ArrayExercises.MergeToArraysSameSizeSorted(x1, x2); LeetCode lc = new LeetCode(); var groupSizes = new int[] { 3, 3, 3, 3, 3, 1, 3 }; var List111 = OneDimensionalArray.GroupThePeople(groupSizes); int[][] indices = new int[3][] { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } }; lc.OddCells(2, 3, indices); }
public void MaxProfitTest_ShouldReturn_2_CosApparentlyItIsPossibleToBuyFor0(int[] prices, int output) { int actual = LeetCode.MaxProfit(prices); Assert.AreEqual(output, actual); }
public void MaxProfitTest_ShouldNOT_TakeInAccountBoughtPossibilitesThatComeTooLate(int[] prices, int output) { int actual = LeetCode.MaxProfit(prices); Assert.AreEqual(output, actual); }
public void MaxProfitTest_ShouldReturn_0_WhenPricesDecrease(int[] prices, int output) { int actual = LeetCode.MaxProfit(prices); Assert.AreEqual(output, actual); }
private static void Main(string[] args) { QuestionHelpers.Time(() => new Solution().SplitArray(LeetCode.Array(), LeetCode.Int())); }
private static void Main(string[] args) { QuestionHelpers.Time(() => new Solution().NumDecodings(LeetCode.String())); }