<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example 1: ``` Input: [ [1,1,1], [1,0,1], [1,1,1] ] Output: [ [1,0,1], [0,0,0], [1,0,1] ] ``` Example 2: ``` Input: [ [0,1,2,0], [3,4,5,2], [1,3,1,5] ] Output: [ [0,0,0,0], [0,4,5,0], [0,3,1,0] ] ``` ``` /** * @param {number[][]} matrix * @return {void} Do not return anything, modify matrix in-place instead. */ **本題的思路是用第一行來保存其余行中某列是否為0元素。例如:第二行第三列為0,則將第一行第三列置為0,然后將第二行全部置為0。行的方向判斷完后,就看第一行哪些元素為0,將0元素所在的列置為0。 不過,直接這樣會覆蓋原先第一行本就有的0,所以一開始要先遍歷第一行,只需記錄第一行是否有0,在最后,再根據第一行是否有0,來決定第一行是否需要全部置為0。 于是,具體步驟如下: 1、遍歷第一行,看有沒有0 2、從第二行開始遍歷,若當前行有0,則在第一行中對應列的元素變為0,并將該行都置為0 3、遍歷第一行,將0元素所在的列都置為0 4、若第一行本就有0,則將第一行全部置為0 var setZeroes = function(matrix) { let m = matrix.length, n = matrix[0].length let firstRowContains0 = false // 遍歷第一行,看有沒有0 for (let col = 0; col < n; col++) { if (matrix[0][col] === 0) { firstRowContains0 = true break } } // 從第二行開始遍歷 for (let row = 1; row < m; row++) { let thisRowContains0 = false// 若當前行有0, 則在第一行中對應列的元素變為0 for (let col = 0; col < n; col++) { if (matrix[row][col] === 0) { matrix[0][col] = 0 thisRowContains0 = true } }// 若這行有0, 則把這一行都置為0 if (thisRowContains0) { for (let col = 0; col < n; col++) matrix[row][col] = 0 } } // 遍歷第一行,將0元素所在的列都置為0 for (let col = 0; col < n; col++) { if (matrix[0][col] === 0) { for (let row = 1; row < m; row++) { matrix[row][col] = 0 } } } // 最后,若第一行本來有0元素,就把第一行都置為0 if (firstRowContains0) { for (let col = 0; col < n; col++) matrix[0][col] = 0 } }; ```
                  <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>

                              哎呀哎呀视频在线观看