From 5d21125e56b995896fd255633ae5b957c85446a0 Mon Sep 17 00:00:00 2001 From: Shafaqun Nisa Date: Fri, 3 Oct 2025 03:36:23 +0530 Subject: [PATCH] 36.Valid Sudoku.cpp --- 36.Valid Sudoku.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 36.Valid Sudoku.cpp diff --git a/36.Valid Sudoku.cpp b/36.Valid Sudoku.cpp new file mode 100644 index 0000000..7a37a4c --- /dev/null +++ b/36.Valid Sudoku.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + bool isValidSudoku(vector>& board) { + bitset<9> Col[9]; + bitset<9> Row[9]; + bitset<9> Block[9]; + + for(int i=0; i<9; i++){ + for(int j=0; j<9; j++){ + char c = board[i][j]; + if (c == '.') continue; + int x=(c-'0')%9; + // Convert the character digit to an index (0-8) 0 for 9 + + if (Row[i][x]) return 0; + Row[i][x] = 1; + + if (Col[j][x]) return 0; + Col[j][x] = 1; + + int bidx = (i / 3) * 3 + j / 3; + if (Block[bidx][x]) return 0; + Block[bidx][x] = 1; + } + } + return 1; + } +};