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. (找到最大的整数k使得n! % s^k ==0) (求n!在b进制下末尾0的个数) (区间满足个数)

    题目:https://codeforces.com/contest/1114/problem/C 将b分解为若干素数乘积,记录每个素数含多少次方 b = p1^y1·p2^y2·...·pm^ym. ...

  2. 使用手淘flexible.js适配移动端布局

    下载flexible: https://github.com/amfe/lib-flexible //未压缩版 (function flexible (window, document) { var ...

  3. [转] 在body中没有元素把高度撑开的情况下,设置全屏

    [From] https://segmentfault.com/q/1010000006182839 html,body { margin:; padding:; min-height: 100vh; ...

  4. python (2) 之 pyc

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本正常的,但执行报错"AttributeError: 'module' object has no attribute ' ...

  5. PIE SDK打开长时间序列数据

    1. 功能简介 时间序列数据(time series data)是在不同时间上收集到的数据,这类数据是按时间顺序收集到的,用于所描述现象随时间变化的情况.当前随着遥感卫星技术日新月异的发展,遥感卫星的 ...

  6. Yii1 的数据库操作整理

    1.根据条件查询一个集合 $objectResult=Post::model()->findAll($condition,$params);$objectResult=Post::model() ...

  7. Linux批量杀掉挂掉的进程

    $ `ps aux | grep test | grep -v grep | awk '{print $2}'` 杀掉含有test且不含有grep的进程,后面的 awk '{print $2}' 是进 ...

  8. spring IoC源码分析 (3)Resource解析

    引自 spring IoC源码分析 (3)Resource解析 定义好了Resource之后,看到XmlFactoryBean的构造函数 public XmlBeanFactory(Resource  ...

  9. Map接口常用实现类学习

    HashMap 1.6的HashMap:数组加单向链表结构 最重要的内部类Entry,全类名是java.util.HashMap.Entry,是个静态类,实现了Map.Entry接口.HashMap. ...

  10. 企业的VI设计需要包含哪些元素

    VI设计,即视觉识别系统,企业VI设计是企业品牌建设的重中之重.最近很多人都在问,一套完整的企业VI设计都包括哪些内容?现在我们站在一个高级设计师的角度,来简单谈一谈VI设计包括哪些内容.文中指出,一 ...