I've been stuck on this for hours so am brining it here to see if i can get any suggestions..
I have an array that i need to check to see if there are any duplicate values present. I do not need to remove the duplicates, just see if any are present. If there are duplicates, the method should return false; if there are no duplicates, the method should return true. My method keeps returning true. My code is below.
(its not a sudoku solver, but just a solution validator)
Expand|Select|Wrap|Line Numbers
- private static boolean isSolution(Sudoku puzzle)
- {
- int count=0;
- boolean solution = false;
- for (Cell[] myPuzzle : puzzle)
- {
- for (int i=0; i<myPuzzle.length; i++)
- {
- for (int j=i+1; j<myPuzzle.length; j++)
- {
- if (myPuzzle[i] == myPuzzle[j])
- count++;
- }
- }
- }
- if (count > 0)
- solution= false;
- else
- solution = true;
- return solution;
- }
any insight would be greatly appreciated.