✅ Help LeetCode Problem
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Numerics;
using System.Reflection;
using System.Xml;
namespace Program
{
class Exercise
{
static void Main(string[] args)
{
int[] nums1 = { 1, 1, 1, 2, 2, 3 };
Console.WriteLine(RemoveDuplicates(nums1));
}
static int RemoveDuplicates(int[] nums)
{
int count = 0;
int t = 1;
Array.Sort(nums);
for (int i = 0; i < nums.Length - 1; i++)
{
if (nums[i] == nums[i+1])
{
count++;
}
else
{
count = 0;
}
if (count > 1)
{
for (int m = i+1; m < nums.Length; m++)
{
if (nums[m] == nums[i-1])
{
nums[m] = nums[nums.Length-t];
t++;
}
}
}
}
Array.Resize(ref nums, nums.Length-t+1);
Array.Sort(nums);
for (int x = 0; x < nums.Length; x++)
{
Console.WriteLine(nums[x]);
}
return nums.Length;
}
}
}
I tried running this code in Visual Studious and the result was different from leetcode (Visual Studios game the correct answer)
2 Replies
Visual Studios game the correct answerassuming you meant "gave", no, it doesn't appear that it did
(this was solved in #chat )