<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Valid Sudoku ### Source - leetcode: [Valid Sudoku | LeetCode OJ](https://leetcode.com/problems/valid-sudoku/) - lintcode: [(389) Valid Sudoku](http://www.lintcode.com/en/problem/valid-sudoku/) ~~~ Determine whether a Sudoku is valid. The Sudoku board could be partially filled, where empty cells are filled with the character .. Example The following partially filed sudoku is valid. ~~~ ![valid-sudoku.png](https://box.kancloud.cn/2015-10-24_562b1f6d4bac6.png) ~~~ Valid Sudoku Note A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated. Clarification What is Sudoku? http://sudoku.com.au/TheRules.aspx https://zh.wikipedia.org/wiki/%E6%95%B8%E7%8D%A8 https://en.wikipedia.org/wiki/Sudoku http://baike.baidu.com/subview/961/10842669.htm ~~~ ### 題解 看懂數獨的含義就好了,分為三點考慮,一是每行無重復數字;二是每列無重復數字;三是小的九宮格中無重復數字。 ### Java ~~~ class Solution { /** * @param board: the board @return: wether the Sudoku is valid */ public boolean isValidSudoku(char[][] board) { if (board == null || board.length == 0) return false; // check row for (int i = 0; i < 9; i++) { boolean[] numUsed = new boolean[9]; for (int j = 0; j < 9; j++) { if (isDuplicate(board[i][j], numUsed)) { return false; } } } // check column for (int i = 0; i < 9; i++) { boolean[] numUsed = new boolean[9]; for (int j = 0; j < 9; j++) { if (isDuplicate(board[j][i], numUsed)) { return false; } } } // check sub box for (int i = 0; i < 9; i = i + 3) { for (int j = 0; j < 9; j = j + 3) { if (!isValidBox(board, i, j)) { return false; } } } return true; } private boolean isValidBox(char[][] box, int x, int y) { boolean[] numUsed = new boolean[9]; for (int i = x; i < x + 3; i++) { for (int j = y; j < y + 3; j++) { if (isDuplicate(box[i][j], numUsed)) { return false; } } } return true; } private boolean isDuplicate(char c, boolean[] numUsed) { if (c == '.') { return false; } else if (numUsed[c - '1']) { return true; } else { numUsed[c - '1'] = true; return false; } } } ~~~ ### 源碼分析 首先實現兩個小的子功能模塊判斷是否有重復和小的九宮格是否重復。 ### 復雜度分析 略 ### Reference - Soulmachine 的 leetcode 題解
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看