< Summary

Information
Class: LeetCode.Algorithms.CountOperationsToObtainZero.CountOperationsToObtainZeroSubtraction
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountOperationsToObtainZero\CountOperationsToObtainZeroSubtraction.cs
Line coverage
90%
Covered lines: 19
Uncovered lines: 2
Coverable lines: 21
Total lines: 54
Line coverage: 90.4%
Branch coverage
75%
Covered branches: 9
Total branches: 12
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CountOperations(...)75%121290.47%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountOperationsToObtainZero\CountOperationsToObtainZeroSubtraction.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 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.CountOperationsToObtainZero;
 13
 14/// <inheritdoc />
 15public sealed class CountOperationsToObtainZeroSubtraction : ICountOperationsToObtainZero
 16{
 17    /// <summary>
 18    ///     Time complexity - O(max(num1, num2))
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="num1"></param>
 22    /// <param name="num2"></param>
 23    /// <returns></returns>
 24    public int CountOperations(int num1, int num2)
 225    {
 226        if (num1 == 0 || num2 == 0)
 027        {
 028            return 0;
 29        }
 30
 231        if (num1 == num2)
 132        {
 133            return 1;
 34        }
 35
 136        var count = 0;
 37
 438        while (num1 != 0 && num2 != 0)
 339        {
 340            if (num1 > num2)
 141            {
 142                num1 -= num2;
 143            }
 44            else
 245            {
 246                num2 -= num1;
 247            }
 48
 349            count++;
 350        }
 51
 152        return count;
 253    }
 54}