Leetcode: Sudoku Solver

July 19, 2015

 

Problem statement:

Write a program to solve a Sudoku puzzle by filling the empty cells.

Empty cells are indicated by the character '.'.

You may assume that there will be only one unique solution.

 

Solution 1: 

 

Great blog to read:

 

http://blog.csdn.net/fightforyourdream/article/details/16916985

 

And then, start to implement the solution using C# code:

 

https://github.com/jianminchen/sudokuSolver/blob/master/Program.cs

 

Solution 2: 

 

Read the blog,

http://blog.csdn.net/linhuanmars/article/details/20748761

 

and then, implement the solution using c# code:

 

https://github.com/jianminchen/sudokuSolver/blob/master/Program2.cs

 

Solution 3: (good workout on C# KeyValuePair class)

 

and then, convert C++ code to C# code from the blog:

https://github.com/yinlinglin/LeetCode/blob/master/SudokuSolver.h

 

Excellent code in C++, using class for node on the board. Learn a few things, fun to play with the code

 

C# code:

https://github.com/jianminchen/sudokuSolver/blob/master/Program3.cs

 

solution 4:

https://github.com/jianminchen/sudokuSolver/blob/master/Program4.cs

source code from the blog:

https://github.com/xiaoxq/leetcode-cpp/blob/master/src/SudokuSolver.cpp

 

Solution 5:

read the blog: (Good coding! practice more based on this blog)

https://github.com/zwxxx/LeetCode/blob/master/Sudoku_Solver.cpp

 

and convert the C++ code to C# code, (great workout on C# LinkedList for blank nodes)

 

https://github.com/jianminchen/sudokuSolver/blob/master/Program5.cs

 

Solution 6:

read the blog:

http://shanjiaxin.blogspot.ca/2014/04/sudoku-solver-leetcode.html

 

and convert Java code to C# code, great workout on C# and logic checking "return false"

 

https://github.com/jianminchen/sudokuSolver/blob/master/Program6.cs

 

Solution 7:

blog:

http://www.jiuzhang.com/solutions/sudoku-solver/

C# code:

https://github.com/jianminchen/sudokuSolver/blob/master/Program7.cs

 

Solution 8:

Thanks for the blog's highlight line of code on back tracking; finally, I got it! My logic thinking has flaws on back tracking;

extra backtracking is not a good. Minimize the back tracking, only do it when "return false". It makes sense to do that.

 

blog:

http://bangbingsyb.blogspot.ca/2014/11/leetcode-valid-sudoku-sudoku-solver.html

C# code:

https://github.com/jianminchen/sudokuSolver/blob/master/Program8.cs

 

Solution 10:

blog: (Excellent implementation! no extra line or number in the code! Best for memorization! Go through other solutions later. )

https://github.com/rffffffff007/leetcode/blob/master/Sudoku%20Solver.java

 

C# code:

https://github.com/jianminchen/sudokuSolver/blob/master/Program10.cs

 

算法理解了, 代码可以记住了; 开始看不同的题解, 看看高手的代码; 从不同的题解中, 模仿模仿! 像打网球, 多接触不同的打法,

开阔眼界; 接着看这道题的题解. 试着从不同角度看一个问题, 多练习改代码; 看自己能不能有自己的看法, 去尝试一点更改,

玩一点花样; 增加练习C#编程的机会.

 

Also, the code written has been work on readability, learned through my favorite book reading:

http://shop.oreilly.com/product/9780596802301.do

 

Those favorite rules I like to learn, pick up and follow:

Big fan of DRY (Do not repeat yourself) principle, do one thing a time, break giant expression, using explaining variable or summary

variable, and abstract the thing to a function, extract a subproblem to a function. The code is also modified to fit into short memory,

less mental baggage to read through. 

 

 

 

Read solutions:

 

https://github.com/jordandong/myleetcodes/blob/master/SudokuSolver.cpp

 

https://github.com/Sayericplz/myleetcode/blob/master/isValidSudoku.cpp

 

 

BFS, using queue - try to convert it to C#

http://yucoding.blogspot.ca/2013/12/leetcode-question-sudoku-solver.html

 

转载于:https://www.cnblogs.com/juliachenOnSoftware/p/4689010.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值