Question: ///Need help finding howmany unique numbers are present in a list using recursion public static int numUnique(double[] list) { return numberUniqueHelper(list, 1); } public static
///Need help finding howmany unique numbers are present in a list using recursion
public static int numUnique(double[] list) { return numberUniqueHelper(list, 1); }
public static int numberUniqueHelper(double [] list, int cursor) { int lengthus= list.length; int numUnique= 1; //automatically giving us duplicate 1 if size is bigger than 0 which is true; if ( lengthus== 0 || list== null) { numUnique= 0; } if (cursor < lengthus) { if ( list[cursor] != list[cursor-1] ) { numberUniqueHelper(list, cursor+1); numUnique++; } numberUniqueHelper(list, cursor+1); } return numUnique;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
