diff --git a/26. Remove Duplicates from Sorted Array/26. Remove Duplicates from Sorted Array.csproj b/26. Remove Duplicates from Sorted Array/26. Remove Duplicates from Sorted Array.csproj new file mode 100644 index 0000000..82c091f --- /dev/null +++ b/26. Remove Duplicates from Sorted Array/26. Remove Duplicates from Sorted Array.csproj @@ -0,0 +1,11 @@ + + + + Exe + net10.0 + _26._Remove_Duplicates_from_Sorted_Array + enable + enable + + + diff --git a/26. Remove Duplicates from Sorted Array/Program.cs b/26. Remove Duplicates from Sorted Array/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/26. Remove Duplicates from Sorted Array/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/26. Remove Duplicates from Sorted Array/Solution.cs b/26. Remove Duplicates from Sorted Array/Solution.cs new file mode 100644 index 0000000..fab71f8 --- /dev/null +++ b/26. Remove Duplicates from Sorted Array/Solution.cs @@ -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; + } +} \ No newline at end of file diff --git a/Leetcode.sln b/Leetcode.sln index 69f90ff..3193445 100644 --- a/Leetcode.sln +++ b/Leetcode.sln @@ -187,6 +187,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18. 4Sum", "18. 4Sum\18. 4S 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}" 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 GlobalSection(SolutionConfigurationPlatforms) = preSolution 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|x86.ActiveCfg = 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 GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE