< Summary

Information
Class: LeetCode.Algorithms.SortAnArray.SortAnArrayQuickSort
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SortAnArray\SortAnArrayQuickSort.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 61
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
SortArray(...)100%11100%
SortArray(...)100%22100%
Partition(...)100%44100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SortAnArray\SortAnArrayQuickSort.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.SortAnArray;
 13
 14/// <inheritdoc />
 15public class SortAnArrayQuickSort : ISortAnArray
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n log n)
 19    ///     Space complexity - O(n log n)
 20    /// </summary>
 21    /// <param name="nums"></param>
 22    /// <returns></returns>
 23    public int[] SortArray(int[] nums)
 224    {
 225        SortArray(nums, 0, nums.Length - 1);
 26
 227        return nums;
 228    }
 29
 30    private static void SortArray(IList<int> nums, int left, int right)
 1431    {
 1432        if (left >= right)
 833        {
 834            return;
 35        }
 36
 637        var partitionIndex = Partition(nums, left, right);
 38
 639        SortArray(nums, left, partitionIndex - 1);
 640        SortArray(nums, partitionIndex + 1, right);
 1441    }
 42
 43    private static int Partition(IList<int> array, int low, int high)
 644    {
 4245        for (var j = low; j < high; j++)
 1546        {
 1547            if (array[j] > array[high])
 1048            {
 1049                continue;
 50            }
 51
 552            (array[low], array[j]) = (array[j], array[low]);
 53
 554            low++;
 555        }
 56
 657        (array[low], array[high]) = (array[high], array[low]);
 58
 659        return low;
 660    }
 61}