26. Remove Duplicates from Sorted Array
This commit is contained in:
@@ -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>
|
||||||
2
26. Remove Duplicates from Sorted Array/Program.cs
Normal file
2
26. Remove Duplicates from Sorted Array/Program.cs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
Console.WriteLine("Hello, World!");
|
||||||
16
26. Remove Duplicates from Sorted Array/Solution.cs
Normal file
16
26. Remove Duplicates from Sorted Array/Solution.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Leetcode.sln
14
Leetcode.sln
@@ -187,6 +187,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18. 4Sum", "18. 4Sum\18. 4S
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "23. Merge k Sorted Lists", "23. Merge k Sorted Lists\23. Merge k Sorted Lists.csproj", "{B586286C-CBA7-4AF0-A2B3-E488639B2E5C}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "23. Merge k Sorted Lists", "23. Merge k Sorted Lists\23. Merge k Sorted Lists.csproj", "{B586286C-CBA7-4AF0-A2B3-E488639B2E5C}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "26. Remove Duplicates from Sorted Array", "26. Remove Duplicates from Sorted Array\26. Remove Duplicates from Sorted Array.csproj", "{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -1301,6 +1303,18 @@ Global
|
|||||||
{B586286C-CBA7-4AF0-A2B3-E488639B2E5C}.Release|x64.Build.0 = Release|Any CPU
|
{B586286C-CBA7-4AF0-A2B3-E488639B2E5C}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{B586286C-CBA7-4AF0-A2B3-E488639B2E5C}.Release|x86.ActiveCfg = Release|Any CPU
|
{B586286C-CBA7-4AF0-A2B3-E488639B2E5C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{B586286C-CBA7-4AF0-A2B3-E488639B2E5C}.Release|x86.Build.0 = Release|Any CPU
|
{B586286C-CBA7-4AF0-A2B3-E488639B2E5C}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{5CE01D6E-7C12-45DC-8C26-DFE67F16AD3F}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user