< Summary

Information
Class: LeetCode.Algorithms.RemoveDuplicatesFromSortedArray2.RemoveDuplicatesFromSortedArray2TwoPointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\RemoveDuplicatesFromSortedArray2\RemoveDuplicatesFromSortedArray2TwoPointers.cs
Line coverage
86%
Covered lines: 13
Uncovered lines: 2
Coverable lines: 15
Total lines: 46
Line coverage: 86.6%
Branch coverage
83%
Covered branches: 5
Total branches: 6
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
RemoveDuplicates(...)83.33%6686.66%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\RemoveDuplicatesFromSortedArray2\RemoveDuplicatesFromSortedArray2TwoPointers.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.RemoveDuplicatesFromSortedArray2;
 13
 14/// <inheritdoc />
 15public class RemoveDuplicatesFromSortedArray2TwoPointers : IRemoveDuplicatesFromSortedArray2
 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 RemoveDuplicates(int[] nums)
 224    {
 225        if (nums.Length <= 2)
 026        {
 027            return nums.Length;
 28        }
 29
 230        var left = 2;
 31
 2632        for (var right = 2; right < nums.Length; right++)
 1133        {
 1134            if (nums[right] == nums[left - 2])
 335            {
 336                continue;
 37            }
 38
 839            nums[left] = nums[right];
 40
 841            left++;
 842        }
 43
 244        return left;
 245    }
 46}