From 87cbf79aa0b6ec5156ffdd1239d6f319b97d1736 Mon Sep 17 00:00:00 2001 From: MITHILESH Date: Thu, 1 Oct 2020 12:53:37 +0530 Subject: [PATCH] Create valid soduku.cpp --- cpp/valid soduku.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cpp/valid soduku.cpp diff --git a/cpp/valid soduku.cpp b/cpp/valid soduku.cpp new file mode 100644 index 0000000000..46637abb9d --- /dev/null +++ b/cpp/valid soduku.cpp @@ -0,0 +1,21 @@ +class Solution { +public: + bool isValidSudoku(vector>& board) { + int rows[9][10]; + int cols[9][10]; + int boxes[9][10]; + memset(rows, 0, sizeof(rows)); + memset(cols, 0, sizeof(cols)); + memset(boxes, 0, sizeof(boxes)); + for(int i = 0; i < 9; i++) { + for(int j = 0; j < 9; j++) { + if (board[i][j] != '.') { + int num = board[i][j] - '0'; + if (++rows[i][num] > 1 || ++cols[j][num] > 1 || ++boxes[(i/3)*3 + j/3][num] > 1) return false; + + } + } + } + return true; + } +};