Skip to content

top145-#36 #5

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
LionCoder4ever opened this issue Sep 30, 2021 · 0 comments
Open

top145-#36 #5

LionCoder4ever opened this issue Sep 30, 2021 · 0 comments

Comments

@LionCoder4ever
Copy link
Owner

  • map
class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        // brust way
        int a[9][9];
        for(int i=0;i<9;i++) {
            for(int j=0;j<9;j++) {
                a[i][j] = board[i][j] == '.' ? - 1 : board[i][j] - '0';
            }
        }
        int b[10][10], c[10][10];
        int d[3][3][10];
        for(int i=0;i<10;i++) {
            for(int j=0;j<10;j++) {
                b[i][j] = 0;
                c[i][j] = 0;
            }
        }
        for(int i=0;i<3;i++) {
            for(int j=0;j<3;j++) {
                for(int k=0;k<10;k++) {
                    d[i][j][k] = 0;
                }
            }
        }
        for(int i=0;i<9;i++) {
            for(int j=0;j<9;j++) {
                if(a[i][j] != -1) {
                    b[i][a[i][j]]++;
                    if(b[i][a[i][j]] > 1) return false;

                    c[j][a[i][j]]++;
                    if(c[j][a[i][j]] > 1) return false;

                    d[i/3][j/3][a[i][j]]++;
                    if(d[i/3][j/3][a[i][j]] > 1) return false;
                    }
                }
                
            }
        return true;
    }
};
LionCoder4ever added a commit that referenced this issue Jul 15, 2022
LionCoder4ever added a commit that referenced this issue Jul 15, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant