< Summary

Information
Class: LeetCode.Algorithms.CountOperationsToObtainZero.CountOperationsToObtainZeroDivision
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountOperationsToObtainZero\CountOperationsToObtainZeroDivision.cs
Line coverage
90%
Covered lines: 20
Uncovered lines: 2
Coverable lines: 22
Total lines: 56
Line coverage: 90.9%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CountOperations(...)83.33%121290.9%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountOperationsToObtainZero\CountOperationsToObtainZeroDivision.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 CountOperationsToObtainZeroDivision : ICountOperationsToObtainZero
 16{
 17    /// <summary>
 18    ///     Time complexity - O(log(min(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
 338        while (num1 != 0 && num2 != 0)
 239        {
 240            if (num1 > num2)
 141            {
 142                count += num1 / num2;
 43
 144                num1 %= num2;
 145            }
 46            else
 147            {
 148                count += num2 / num1;
 49
 150                num2 %= num1;
 151            }
 252        }
 53
 154        return count;
 255    }
 56}