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.

    思路:

    思路很简单,只要检查每行、每列、每个子区域中没有重复的数字即可。

    代码:

     1     bool isValidSudoku(vector<vector<char> > &board) {
     2         // Note: The Solution object is instantiated only once and is reused by each test case.
     3         map<char, int> table;
     4         for(int i = 0; i < 9; i++){
     5             table.clear();
     6             for(int j = 0; j < 9; j++){
     7                 if(board[i][j] != '.'){
     8                     if(table.find(board[i][j]) != table.end())
     9                         return false;
    10                     else
    11                         table[board[i][j]] = 1;
    12                 }
    13             }
    14         }
    15         for(int i = 0; i < 9; i++){
    16             table.clear();
    17             for(int j = 0; j < 9; j++){
    18                 if(board[j][i] != '.'){
    19                     if(table.find(board[j][i]) != table.end())
    20                         return false;
    21                     else
    22                         table[board[j][i]] = 1;
    23                 }
    24             }
    25         }
    26         for(int i = 0; i < 9; i++){
    27             table.clear();
    28             for(int j = 0; j < 3; j++){
    29                 for(int k = 0; k < 3; k++){
    30                     if(board[3*(i/3)+j][3*(i%3)+k] != '.'){
    31                         if(table.find(board[3*(i/3)+j][3*(i%3)+k]) != table.end())
    32                             return false;
    33                         else
    34                             table[board[3*(i/3)+j][3*(i%3)+k]] = 1;
    35                     }
    36                 }
    37             }
    38         }
    39         return true;
    40     }
  • 相关阅读:
    bootstrap2文档的学习
    在mininet上基于ovs,ovx,pox搭建三点虚拟网络
    借鉴一些关于js框架的东西
    setTimeout js
    Ubuntu 上配置静态的ip
    html5 canvas
    获取当前页面的长宽
    ovs的卸载
    tensorflow实现Word2vec
    梯度下降做做优化(batch gd、sgd、adagrad )
  • 原文地址:https://www.cnblogs.com/waruzhi/p/3415534.html
Copyright © 2011-2022 走看看