This commit is contained in:
Electrominch
2022-10-07 00:48:29 +03:00
parent c388b14c3f
commit 0b88604037
20 changed files with 414 additions and 7 deletions

View File

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

View File

@@ -0,0 +1,12 @@
namespace _283._Move_Zeroes
{
internal class Program
{
static void Main(string[] args)
{
var test = new int[] { 0, 1, 0, 3, 12 };
new Solution().MoveZeroes(test);
Console.WriteLine(String.Join(" ", test));
}
}
}

View File

@@ -0,0 +1,20 @@
namespace _283._Move_Zeroes;
public class Solution
{
public void MoveZeroes(int[] nums)
{
for(int i = 0; i < nums.Length-1; i++)
{
if (nums[i] != 0)
continue;
int nonZeroIndex = i + 1;
while (nonZeroIndex < nums.Length && nums[nonZeroIndex] == 0)
nonZeroIndex++;
if (nonZeroIndex >= nums.Length)
break;
nums[i] = nums[nonZeroIndex];
nums[nonZeroIndex] = 0;
}
}
}