Hey, i am new to this forum(first question here).
So Here my problem is that i have this code and the last return statement it says "cannot implicitly convert int to int[]".
Earlier i did a few tweaks to code but no luck can't find the solution!
Now here's the code
- using System;
-
- public class Program
- {
- public static void Main()
- {
- Console.WriteLine(FindDuplicates([1,2,2,3]));
- }
-
- public int[] FindDuplicates(int[] nums)
- {
- var tortoise = nums[0];
- var hare = nums[0];
- while(true)
- {
- tortoise = nums[tortoise];
- hare = nums[nums[hare]];
- if(tortoise == hare)
- break;
- }
-
- var ptr1 = nums[0];
- var ptr2 = nums[tortoise];
-
- while(ptr1 != ptr2)
- {
- ptr1 = nums[ptr1];
- ptr2 = nums[ptr2];
- }
-
- return ptr1;
- }
- }