コード例 #1
0
        public void NumJewelsInStonesMethodTest()
        {
            JewelsAndStones jewelsAndStones = new JewelsAndStones();

            Assert.AreEqual(3, jewelsAndStones.NumJewelsInStones("aA", "aAAbbbb"));
            Assert.AreEqual(0, jewelsAndStones.NumJewelsInStones("z", "ZZ"));
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: parisajabbari/LeetCode
        public void Test1()
        {
            string s = "aAAbbbb";
            string j = "aA";

            Assert.Equal(3, JewelsAndStones.NumJewelsInStones(j, s));
        }
コード例 #3
0
        public void NumJewelsInStonesTest()
        {
            var solution = new JewelsAndStones();

            Assert.Equal(3, solution.NumJewelsInStones("aA", "aAAbbbb"));
            Assert.Equal(0, solution.NumJewelsInStones("z", "ZZ"));
        }
コード例 #4
0
        public void JewelsAndStones_ReturnsCorrectNumberOfStones()
        {
            int             actual;
            int             expected        = 3;
            JewelsAndStones jewelsAndStones = new JewelsAndStones();

            actual = jewelsAndStones.NumJewelsInStones("aA", "aAAbbbb");
            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
        public void NumJewelsInStonesTest()
        {
            JewelsAndStones l = new JewelsAndStones();

            string J = "aA", S = "aAAbbbb";

            Assert.AreEqual(3, l.NumJewelsInStones(J, S));

            J = "z";
            S = "ZZ";
            Assert.AreEqual(0, l.NumJewelsInStones(J, S));
        }
コード例 #6
0
        public void CheckValidOutputExample1()
        {
            //Arrange
            var JaS  = new JewelsAndStones();
            var J    = "aA";
            var S    = "aAAbbbb";
            int exep = 3;

            //Act
            var output = JaS.NumJewelsInStones(J, S);

            //Assert
            Assert.Equal(exep, output);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: holdens3/LeetCode
        public static void Main()
        {
            int [] answer = SmallerNumbersThanCurrent(0, 1, 2, 3, 4, 5, 6, 7, 11);

            int response = ReduceToZero.NumberOfSteps(14);

            response = Max69.Maximum69Number(9669);

            ListNode head   = new ListNode(1);
            ListNode second = new ListNode(0);

            head.next = second;
            ListNode third = new ListNode(1);

            second.next = third;

            GetDecimalValue.GetDecimal(head);

            BalancedString.GetBalancedCount("RLRRRLLRLL");

            string stones = "aAAbbbb";
            string jewels = "aA";
            int    count  = JewelsAndStones.GetJewelCount(jewels, stones);

            int[] digits = { 12, 345, 2, 6, 7896 };
            int   J      = EvenDigits.NumEvenDigits(digits);

            int i = SubtractProdAndSum.SubtractProductAndSum(234);

            char[] values = new char[] { 'a', 'a', 'b', 'b', 'c', 'c', 'c' };
            StringCompression.StringCompression.Compress(values);


            int[] input = new int[] { 3, 2, 3, 4, 3, 3 };
            Console.WriteLine("Result is: {1}", Decompress.Decompress.DecompressRLElist(input));
        }
コード例 #8
0
        public static void Main()
        {
            string[] transactions = { "bob,627,1973,amsterdam", "alex,387,885,bangkok", "alex,355,1029,barcelona", "alex,587,402,bangkok", "chalicefy,973,830,barcelona", "alex,932,86,bangkok", "bob,188,989,amsterdam" };
            int[]    test         = { 0, 1, 2, 3, 4, 5, 6, 0, 1 };
            int[]    test2        = { 1, 3, 5, 2 };
            string[] tests        = { "bella", "label", "roller" };
            string   input2       = "10#11#12";

            string something = Program.Mapping.FreqAlphabets(input2);

            Ranks instanceOfRanks = new Ranks();

            string[] medals = instanceOfRanks.FindRelativeRanks(test2);


            int         response4 = WordLength.LengthOfLastWord("b   a    ");
            IList <int> response2 = Program.SelfDivide.SelfDividingNumbers(1, 22);

            IList <string> transactionsResponse = Program.Invalid.InvalidTransactions(transactions);

            int[] response = ArrayIntersect.Intersect(test, test2);
            response = ArrayParity.SortArrayByParity(test);

            IList <int> smallAnswer = Smaller.CountSmaller(test);

            IList <string> answers = Common.GetValues(tests);

            int [] answer = Smaller.SmallerNumbersThanCurrent(test);

            // int response = ReduceToZero.NumberOfSteps(14);

            //response = Max69.Maximum69Number(9669);

            ListNode head   = new ListNode(1);
            ListNode second = new ListNode(0);

            head.next = second;
            ListNode third = new ListNode(1);

            second.next = third;

            GetDecimalValue.GetDecimal(head);

            BalancedString.GetBalancedCount("RLRRRLLRLL");

            string stones = "aAAbbbb";
            string jewels = "aA";
            int    count  = JewelsAndStones.GetJewelCount(jewels, stones);

            int[] digits = { 12, 345, 2, 6, 7896 };
            int   J      = EvenDigits.NumEvenDigits(digits);

            int i = SubtractProdAndSum.SubtractProductAndSum(234);

            char[] values = new char[] { 'a', 'a', 'b', 'b', 'c', 'c', 'c' };
            StringCompression.StringCompression.Compress(values);


            int[] input = new int[] { 3, 2, 3, 4, 3, 3 };
            Console.WriteLine("Result is: {1}", Decompress.Decompress.DecompressRLElist(input));
        }
コード例 #9
0
        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
        }
コード例 #10
0
 public void Setup()
 {
     _solution = new JewelsAndStones();
 }
コード例 #11
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();
        }