leetcode 36. Valid Sudoku

数独


 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;
    }
上一篇:在@Valid之后添加一个注解@ModelAttribute("user") SysUser user


下一篇:@Valid和@Validated的总结区分(转)