< Summary

Information
Class: LeetCode.Algorithms.SortColors.SortColorsThreePointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SortColors\SortColorsThreePointers.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 52
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
SortColors(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SortColors\SortColorsThreePointers.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.SortColors;
 13
 14/// <inheritdoc />
 15public class SortColorsThreePointers : ISortColors
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="nums"></param>
 22    public void SortColors(int[] nums)
 223    {
 224        var low = 0;
 225        var mid = 0;
 226        var high = nums.Length - 1;
 27
 1128        while (mid <= high)
 929        {
 930            switch (nums[mid])
 31            {
 32                case 0:
 333                    (nums[low], nums[mid]) = (nums[mid], nums[low]);
 34
 335                    low++;
 336                    mid++;
 37
 338                    break;
 39                case 1:
 340                    mid++;
 41
 342                    break;
 43                case 2:
 344                    (nums[high], nums[mid]) = (nums[mid], nums[high]);
 45
 346                    high--;
 47
 348                    break;
 49            }
 950        }
 251    }
 52}

Methods/Properties

SortColors(System.Int32[])