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.

解题:

将每一行、每一列、每一个九格中的数字分别输入一个大小为9的数组中,记录输入的数字是否重复

代码:

 class Solution {
public:
bool isValidSudoku(vector<vector<char> > &board) {
return isValidRow(board) && isValidColumn(board) && isValidBox(board);
} bool isValidRow(vector<vector<char> > board) {
int count[];
for (int i = ; i < ; ++i) {
memset(count, , sizeof(int) * );
for (int j = ; j < ; ++j) {
if (!add(count, board[i][j]))
return false;
}
}
return true;
} bool isValidColumn(vector<vector<char> > board) {
int count[];
for (int i = ; i < ; ++i) {
memset(count, , sizeof(int) * );
for (int j = ; j < ; ++j) {
if (!add(count, board[j][i]))
return false;
}
}
return true;
} bool isValidBox(vector<vector<char> > board) {
int count[];
int point[][] = {
{, }, {, }, {, }, {, }, {, }, {, }, {, }, {, }, {, }
};
for (int i = ; i < ; ++i) {
memset(count, , sizeof(int) * );
for (int x = ; x < ; ++x) {
for (int y = ; y < ; ++y) {
int abscissa = point[i][] + x;
int ordinate = point[i][] + y;
if (!add(count, board[abscissa][ordinate]))
return false;
}
}
}
return true;
} bool add(int count[], char dig) {
if (dig == '.')
return true;
else
return (++count[dig - '']) == ;
} };

代码疑问:

1、为什么形参设置为board和&board都可以通过编译;

附录:

数独填充算法

【Leetcode】【Easy】Valid Sudoku的更多相关文章

  1. 【LeetCode题意分析&解答】37. Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  2. 【LeetCode题意分析&解答】40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  3. 【LeetCode题意分析&解答】35. Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  4. 【LeetCode题意分析&解答】36. Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  5. 【leetcode刷题笔记】Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  6. 【leetcode刷题笔记】Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  7. ACM金牌选手整理的【LeetCode刷题顺序】

    算法和数据结构知识点图 首先,了解算法和数据结构有哪些知识点,在后面的学习中有 大局观,对学习和刷题十分有帮助. 下面是我花了一天时间花的算法和数据结构的知识结构,大家可以看看. 后面是为大家 精心挑 ...

  8. LeetCode之“散列表”:Valid Sudoku

    题目链接 题目要求: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku boar ...

  9. 【LeetCode算法题库】Day7:Remove Nth Node From End of List & Valid Parentheses & Merge Two Lists

    [Q19] Given a linked list, remove the n-th node from the end of list and return its head. Example: G ...

  10. 【LeetCode每天一题】Longest Valid Parentheses(最长有效括弧)

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

随机推荐

  1. 用leiningen来运行和打包clojure项目

    今天是2017年5月24日.隔壁team用clojure写了个工具,我们要拿来用,于是弄了个leiningen来尝试.还没有最后成功,先记录一下一些连蒙带猜的步骤,以免忘记. 一.单独运行的cloju ...

  2. 关于jstl taglib的错误 Can not find the tag library descriptor for “http://java.sun.com/jstl/core”

    在查了N个帖子之后,决定记录一下关于jstl taglib的配置方法. 首先我遇到的错误是: Can not find the tag library descriptor for "htt ...

  3. Oracle PLSQL INDEX BY Binary_Integer 测试

    [转自] http://blog.chinaunix.net/uid-14669803-id-2921539.html DECLARE TYPE t_list_1 IS TABLE OF VARCHA ...

  4. python 网页爬取数据生成文字云图

    1. 需要的三个包: from wordcloud import WordCloud #词云库 import matplotlib.pyplot as plt #数学绘图库 import jieba; ...

  5. 全网备份脚本rsync

    一,服务端配置 #!/bin/sh ######################################################### #by:kingle # #use: confi ...

  6. 基于原生态Hadoop2.6 HA集群环境的搭建

    hadoop2.6  HA平台搭建   一.条件准备 软件条件: Ubuntu14.04 64位操作系统, jdk1.7 64位,Hadoop 2.6.0,  zookeeper 3.4.6 硬件条件 ...

  7. 【ExtJS】自定义组件datetimefield(二)

    接上[ExtJS]自定义组件datetimefield(一) 第三步:添加按钮事件绑定,获取选定的时间 privates:{ finishRenderChildren: function () { v ...

  8. CF 305C ——Ivan and Powers of Two——————【数学】

    Ivan and Powers of Two time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. php 项目中自定义日志方法

    在现在项目中之前没有定义日志的方法,每次调试起来很麻烦,经常不能输出参数,只能用写日志的方法,一直用file_put_contents很烦躁,于是用了一点时间,写了这样一个方法: <?php / ...

  10. jquery/js不支持ie9以下版本的方法或属性

    1.jquery的trim()去除字符串两边的空格,在ie5~8中不支持此方法.若想替换字符串所有的空格看使用replace()正则替换: var date=" 2014-1 0-  15 ...