网球Leetcode: Sudoku Solver

August 2, 2015

July 19, 2015

在http://zzk.cnblogs.com/ 用”找一查找”, 花了几乎单钟头, 找来比较好的Leetcode博客.

 

Read the leetcode question and solutions:

Problem statement:

  1. Find lowest common ancestor in binary tree:

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

blog of a facebook programmer working on leetcode questions:

Empty cells are indicated by the character '.'.

递归版本:空间O(1),时间O(n)

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

http://www.cnblogs.com/chkkch/archive/2012/11/26/2788795.html

 

Try it myself and compare to solutions in my blog:
http://juliachencoding.blogspot.ca/2015/07/leetcode-lowest-common-ancestor-in.html

Solution 1: 

  1. Reverse nodes in k group

 

http://www.cnblogs.com/lichen782/p/leetcode_Reverse_Nodes_in_kGroup.html

Great blog to read:

http://www.cnblogs.com/grandyang/p/4606710.html

 

  1.  binary tree

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

http://www.cnblogs.com/wwwjieo0/p/3891037.html

 

  1. All 158 leetcode algorithm implementation in git hub:

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

我是怎么招聘程序员的

 

Leetcode solution on git hub (use this one more often, best answer,
author profile: http://coolshell.cn/haoel)

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

https://github.com/haoel/leetcode/tree/master/algorithms

 

  1. Leetcode using C#

Solution 2: 

https://github.com/xisuogu/LeetSharp/tree/master/LeetSharp

 

  1. One more to read

Read the blog,

http://blog.csdn.net/u014674776/article/category/2296455

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 9:

blog:

http://www.cnblogs.com/TenosDoIt/p/3800485.html

 

C# code:

https://github.com/jianminchen/sudokuSolver/blob/master/Program9.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

 

相关文章