分享一道阿里巴巴(蚂蚁金服)Java笔试题

时间:2022-02-25 22:26:15

编写一个函数验证一个给定的9x9 整数矩阵是否符合数独的特性:
a) 每个单元格数字为 1-9
b) 每行的9个数不重复
c) 每列的9个数不重复
d) 如图中分割的9个小3x3矩阵,每个小矩阵里9个数不重复

+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| x | x | x | | | | x | x | x |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| x | x | x | | | | x | x | x |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| x | x | x | | | | x | x | x |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| | | | x | x | x | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| | | | x | x | x | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| | | | x | x | x | | | |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| x | x | x | | | | x | x | x |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| x | x | x | | | | x | x | x |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| x | x | x | | | | x | x | x |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+