Harshil Pandey

Harshil Pandey

  • NA
  • 8
  • 572

Cannot implicity convert int to int[]

Jan 13 2021 7:38 AM
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 
  1. using System;  
  2.                       
  3. public class Program  
  4. {     
  5.     public static void Main()  
  6.     {  
  7.         Console.WriteLine(FindDuplicates([1,2,2,3]));  
  8.     }  
  9.       
  10.     public int[] FindDuplicates(int[] nums)  
  11.     {  
  12.         var tortoise = nums[0];  
  13.         var hare = nums[0];  
  14.         while(true)  
  15.         {  
  16.             tortoise = nums[tortoise];  
  17.             hare = nums[nums[hare]];  
  18.             if(tortoise == hare)  
  19.                 break;  
  20.         }  
  21.           
  22.         var ptr1 = nums[0];  
  23.         var ptr2 = nums[tortoise];  
  24.           
  25.         while(ptr1 != ptr2)  
  26.         {  
  27.             ptr1 = nums[ptr1];  
  28.             ptr2 = nums[ptr2];  
  29.         }  
  30.               
  31.         return ptr1;  
  32.     }  
  33. }

Answers (3)