26. Remove Duplicates from Sorted Array

This commit is contained in:
2026-03-25 19:47:09 +03:00
parent 12912123de
commit 48d637475f
4 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>_26._Remove_Duplicates_from_Sorted_Array</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

View File

@@ -0,0 +1,16 @@
public class Solution {
public int RemoveDuplicates(int[] nums) {
var k = nums.Length;
var putIndex = 0;
for(var i = 0; i < nums.Length; i++)
{
while(i < nums.Length - 1 && nums[i+1] == nums[i])
{
i++;
k--;
}
nums[putIndex++] = nums[i];
}
return k;
}
}