-4

I implemented a diagonal sudoku.

Diagonals must not have repetitions

My algorithm to check the diagonal was.

  1. copy diagonals to arrays left_x and right_x
  2. for(i) for(j) if(left_x[i]==left_x[j]&&i!=j) return false
  3. for(i) for(j) if(right_x[i]==right_x[j]&&i!=j) return false

Is there a better implementation to this in terms of the running time?

CrazyGirl
  • 35
  • 7

1 Answers1

0

Rather than comparing all pairs of values, just count the number of times each number appears. If any count is larger than 1, it's not valid.

Jordi Vermeulen
  • 1,168
  • 1
  • 10
  • 17