< Summary

Information
Class: LeetCode.Algorithms.CountPartitionsWithEvenSumDifference.CountPartitionsWithEvenSumDifferencePrefixSum
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountPartitionsWithEvenSumDifference\CountPartitionsWithEvenSumDifferencePrefixSum.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 53
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CountPartitions(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountPartitionsWithEvenSumDifference\CountPartitionsWithEvenSumDifferencePrefixSum.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.CountPartitionsWithEvenSumDifference;
 13
 14/// <inheritdoc />
 15public sealed class CountPartitionsWithEvenSumDifferencePrefixSum : ICountPartitionsWithEvenSumDifference
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="nums"></param>
 22    /// <returns></returns>
 23    public int CountPartitions(int[] nums)
 324    {
 325        var left = nums[0];
 26
 327        var sum = 0;
 28
 3029        for (var i = 0; i < nums.Length; i++)
 1230        {
 1231            var num = nums[i];
 32
 1233            sum += num;
 1234        }
 35
 336        var right = sum - nums[0];
 37
 338        var count = 0;
 39
 2440        for (var i = 1; i < nums.Length; i++)
 941        {
 942            if ((left - right) % 2 == 0)
 743            {
 744                count++;
 745            }
 46
 947            left += nums[i];
 948            right -= nums[i];
 949        }
 50
 351        return count;
 352    }
 53}

Methods/Properties

CountPartitions(System.Int32[])