标签:val i++ java value code ++ math leetcode ali
数独
function isValidSudoku(board) {
var rows = []//行
var cols = [] // 列
var cubes = []//9宫格
for (var i = 0; i < 9; i++) {
rows.push({})
cols.push({})
cubes.push({})
}
for (var i = 0; i < 9; i++) { //循环行
for (var j = 0; j < 9; j++) {//循环列
var value = board[i][j]
if (value != '.') {
var cubeIndex = 3 * Math.trunc(i / 3) + Math.trunc(j / 3)// 0-8
if (rows[i][value] || cols[j][value] || cubes[cubeIndex][value]) return false;
rows[i][value] = true
cols[j][value] = true
cubes[cubeIndex][value] = true
}
}
}
return true;
}
标签:val i++ java value code ++ math leetcode ali
原文地址:https://www.cnblogs.com/rubylouvre/p/12044181.html