< Summary

Information
Class: LeetCode.Algorithms.LemonadeChange.LemonadeChangeGreedy
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\LemonadeChange\LemonadeChangeGreedy.cs
Line coverage
92%
Covered lines: 23
Uncovered lines: 2
Coverable lines: 25
Total lines: 63
Line coverage: 92%
Branch coverage
87%
Covered branches: 14
Total branches: 16
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
LemonadeChange(...)87.5%161692%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\LemonadeChange\LemonadeChangeGreedy.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.LemonadeChange;
 13
 14/// <inheritdoc />
 15public class LemonadeChangeGreedy : ILemonadeChange
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="bills"></param>
 22    /// <returns></returns>
 23    public bool LemonadeChange(int[] bills)
 524    {
 525        var fiveBills = 0;
 526        var tenBills = 0;
 27
 7728        foreach (var bill in bills)
 3329        {
 3330            switch (bill)
 31            {
 32                case 5:
 1533                    fiveBills++;
 34
 1535                    break;
 1036                case 10 when fiveBills > 0:
 937                    fiveBills--;
 938                    tenBills++;
 39
 940                    break;
 41                case 10:
 142                    return false;
 43                case 20:
 844                    switch (fiveBills)
 45                    {
 546                        case > 0 when tenBills > 0:
 547                            fiveBills--;
 548                            tenBills--;
 549                            break;
 50                        case > 2:
 051                            fiveBills -= 3;
 052                            break;
 53                        default:
 354                            return false;
 55                    }
 56
 557                    break;
 58            }
 2959        }
 60
 161        return true;
 562    }
 63}

Methods/Properties

LemonadeChange(System.Int32[])