有效的数独--leetcode

有效的数独--leetcode_第1张图片

class Solution {
    public boolean isValidSudoku(char[][] board) {
        Set temp=new HashSet<>();
        Set temp1=new HashSet<>();
        boolean tmp=false;
        for(int i=0;i<9;i++){
            for(int j=0;j<9;j++){
                if(board[i][j]!='.'){
                    if(!temp.add(board[i][j])) return false;//检测同行有没有重复的数
                }
                if(board[j][i]!='.'){
                    if(!temp1.add(board[j][i])) return false;//检测同列有没有重复的数
                }
            }
            temp.clear();//每行检测结束,清空set
            temp1.clear();//每列检测结束,清空set
        }
        for(int i=0;i<9;i++){
            for(int k=i/3*3;k

题目来源:https://leetcode-cn.com/

你可能感兴趣的:(有效的数独--leetcode)