讨论/综合讨论/有效数独问题,ide和leetcode结果不一样??/
有效数独问题,ide和leetcode结果不一样??

有效数独问题,ide和leetcode结果不一样??


代码如下,我在ide里返回是true,在leetcode就是false,也没用什么全局变量,所以这是为什么呢?

我的代码

class Solution(object):    
    def isValidSudoku(self, board):
        """
        :type board: List[List[str]]
        :rtype: bool
        """
        maps={}
        keys = []
        for i in range(0, len(board)):
            for j in range(0, len(board[i])):
                if board[i][j] is not '.':
                    cell = (i//3)*3+(j//3)
                    if board[i][j] not in maps.values():
                        maps[str(i)+str(j)+str(cell)] = board[i][j]
                    else:                        
                        for k,v in maps.items():
                            if v == board[i][j]:
                                keys.append(k)
                        for k in keys:
                            if k[0] == str(i) or k[1] == str(j) or k[2] == str(cell):
                                return False
                            else:
                                maps[str(i)+str(j)+str(cell)] = board[i][j]
                        keys.clear()
        return True

测试用例(ide返回true,leetcode返回false)

nums = [
["5","3",".",".","7",".",".",".","."],
["6",".",".","1","9","5",".",".","."],
[".","9","8",".",".",".",".","6","."],
["8",".",".",".","6",".",".",".","3"],
["4",".",".","8",".","3",".",".","1"],
["7",".",".",".","2",".",".",".","6"],
[".","6",".",".",".",".","2","8","."],
[".",".",".","4","1","9",".",".","5"],
[".",".",".",".","8",".",".","7","9"]
]

展开讨论

可能你复制错了,我给你复制过去测试了一下,是True.图片.png