zoukankan      html  css  js  c++  java
  • valid sudoku

    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 '.'.

    A partially filled sudoku which is valid.

    Note:
    A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.

    There are just 3 rules to Sudoku.

    Each row must have the numbers 1-9 occuring just once.
    Each column must have the numbers 1-9 occuring just once.
    And the numbers 1-9 must occur just once in each of the 9 sub-boxes of the grid.

    reference:http://www.cnblogs.com/springfor/p/3884217.html

    先按每行check,如果是'.'说明还没填字,是合法的,往下走,如果没在set中存过就加一下,如果便利过程中出现了在set中存在的key值,说明有重复的数字在一行,不合法,return false。

    再按照这个方法check列。

    最后按照这个方法check小方块。

    注意小方块的ij取法。对于当前这块板子来说,总共有9个小方格,按0~8从左到右依次编号。

    按编号求'/'就是求得当前小方格的第一行横坐标,因为每个小方格有3行,所以循环3次。

    按编号求'%'就是求得当前小方格的第一列纵坐标,因为每个小方格有3列,所以循环3次。 

    对9个小方格依次走一边,就完成了检查小方格的工作。

  • 相关阅读:
    java操作Redis
    Redis安装和基本操作
    IDEA使用教程+JRebel破解
    java环境配置
    qtp10安装步骤(比较完整)
    c++第一章1.6
    软件测试第二章作业
    c++作业22题
    c++第二周阶段小测2
    oracle12c数据库第一周小测验
  • 原文地址:https://www.cnblogs.com/joannacode/p/4430888.html
Copyright © 2011-2022 走看看