036 Valid Sudoku Sudoku effective

See: https: //leetcode.com/problems/valid-sudoku/description/

class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
         for(int i = 0; i < 9; i ++)
        {
            unordered_map<char, bool> m1;   //check i_th row
            unordered_map<char, bool> m2;   //check i_th column
            unordered_map<char, bool> m3;   //check i_th subgrid
            for(int j = 0; j < 9; j ++)
            {
                if(board[i][j] != '.')
                {
                    if(m1[board[i][j]] == true)
                        return false;
                    m1[board[i][j]] = true;
                }
                if(board[j][i] != '.')
                {
                    if(m2[board[j][i]] == true)
                        return false;
                    m2[board[j][i]] = true;
                }
                if(board[i/3*3+j/3][i%3*3+j%3] != '.')
                {
                    if(m3[board[i/3*3+j/3][i%3*3+j%3]] == true)
                        return false;
                    m3[board[i/3*3+j/3][i%3*3+j%3]] = true;
                }
            }
        }
        return true;
    }
};

Reference: http: //www.cnblogs.com/ganganloveu/p/4170632.html

Intelligent Recommendation

[LeetCode Problem Solving Report]036. Valid Sudoku

Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 with...

[Leetcode] 36. Effective Sudoku (Valid Sudoku)

Leetcode - 36 Valid Sudoku (Medium) Description of the topic: Given a 9 × 9 incomplete Sudoku array, determine whether it is legal. Problem Solving: Determine if each row, column, and each 3 &ti...

Leetcode 36. Effective Sudoku (Valid Sudoku)

Determine if a 9x9 Sudoku is valid. only need toAccording to the following rules, verify that the number already filled in is valid. Number1-9It can only appear once in each line. Number1-9It can only...

Valid Sudoku: Sudoku verification

Determine if a Sudoku is valid. Sudoku verification. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially filled sudoku which is valid. Not...

More Recommendation

[LintCode] Valid Sudoku [Sudoku]

Problem Determine whether a Sudoku is valid. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. Example The following partially filed sudoku is valid. Not...

Leet Code 36 Valid Sudoku - Sudoku effective - Java

Original problem linkhttps://leetcode.com/problems/valid-sudoku Analyzing fill a portion only of the number is valid, did not fill the lattice digital character '.'. For each row, each column and each...

Interesting algorithm | LeetCode 36 Valid Sudoku (Effective Sudoku)

I saw a very interesting problem-solving idea when brushing questions today, and I really want to record it for sharing reference. The title is leetcode 36 Valid Sudoku as follows: Determine whether a...

Valid Sudoku

[size=large][color=darkred][b]Title description[/b][/color][/size] Determine if a Sudoku is valid, according to: The Sudoku board could be partially filled, where empty cells are filled with the chara...

valid-sudoku

Description [title] Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character’.’...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top