leetcode36
public class Solution
{
public bool IsValidSudoku(char[,] board)
{
for (int i = ; i < ; i++)
{
var dic = new Dictionary<char, int>();
for (int j = ; j < ; j++)
{
var num = board[i, j];
if (num == '.')
{
continue;
}
if (dic.ContainsKey(num))
{
return false;
}
else
{
dic.Add(num, );
}
}
dic.Clear();
} for (int j = ; j < ; j++)
{
var dic = new Dictionary<char, int>();
for (int i = ; i < ; i++)
{
var num = board[i, j];
if (num == '.')
{
continue;
}
if (dic.ContainsKey(num))
{
return false;
}
else
{
dic.Add(num, );
}
}
dic.Clear();
} for (int a = ; a < ; a++)
{
for (int b = ; b < ; b++)
{
var dic = new Dictionary<char, int>();
for (int i = * a; i < * (a + ); i++)
{
for (int j = * b; j < * (b + ); j++)
{
//Console.Write(i + "," + j + " ");
var num = board[i, j];
if (num == '.')
{
continue;
}
if (dic.ContainsKey(num))
{
return false;
}
else
{
dic.Add(num, );
}
}
}
dic.Clear();
//Console.WriteLine();
}
}
return true;
}
}
leetcode36的更多相关文章
- leetcode36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- [Swift]LeetCode36. 有效的数独 | Valid Sudoku
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to th ...
- LeetCode36.有效的数独 JavaScript
判断一个 9x9 的数独是否有效.只需要根据以下规则,验证已经填入的数字是否有效即可. 数字 1-9 在每一行只能出现一次. 数字 1-9 在每一列只能出现一次. 数字 1-9 在每一个以粗实线分隔的 ...
- Leetcode36.Valid Sudoku有效的数独
判断一个 9x9 的数独是否有效.只需要根据以下规则,验证已经填入的数字是否有效即可. 数字 1-9 在每一行只能出现一次. 数字 1-9 在每一列只能出现一次. 数字 1-9 在每一个以粗实线分隔的 ...
- LeetCode-37.Sudok Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy ...
随机推荐
- opengl去除控制台黑窗口
增加如下语句: #pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\ ...
- HDU - 5628:Clarke and math (组合数&线性筛||迪利克雷卷积)
题意:略. 思路:网上是用卷积或者做的,不太会. 因为上一题莫比乌斯有个类似的部分,所以想到了每个素因子单独考虑. 我们用C(x^p)表示p次减少分布在K次减少里的方案数,由隔板法可知,C(x^p)= ...
- springboot项目启动之后初始化自定义配置类
前言 今天在写项目的时候,需要再springboot项目启动之后,加载我自定义的配置类的一些方法,百度了之后特此记录下. 正文 方法有两种: 1. 创建自定义类实现 CommandLineRunner ...
- C#飞行棋游戏
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Windows Server 2008 R2远程协助选项灰色
管理工具——〉服务器管理器——〉功能——〉添加功能 窗口中"远程服务器管理工具"下边的"远程协助"打上对钩"再点击"下一步" ...
- Java API 操作Redis
针对Redis的Java客户端有很多种,具体查看官网信息:https://redis.io/clients#java 本次测试使用Jedis API,Jedis使用方便,其api方法名称与redis命 ...
- Ubuntu sudo: add-apt-repository: command not found
安装缺少的指令即可 $ sudo apt-get install software-properties-common python-software-properties
- Mac环境下PHPstorm配置xdebug开发调试web程序
一.安装PHP的xdebug扩展 安装xdebug(技巧,为了找到适配的版本,让xdebug网站根据phpinfo()函数输出分析找到对应的方法及安装步骤:如果安装了多个PHP版本的话,尽量用phpi ...
- debian下qt4动态编译
一句话不割,版本4.86 ./configure -prefix /home/用户名/Qt/dynamic -opensource -opengl -confirm-license -no-scrip ...
- HttpClient使用示例
1)使用HttpClient发送GET请求 public class MainActivity extends Activity implements OnClickListener { privat ...