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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 方矩陣的兩個對角線中的行式公共元素 > 原文: [https://www.geeksforgeeks.org/row-wise-common-elements-two-diagonals-square-matrix/](https://www.geeksforgeeks.org/row-wise-common-elements-two-diagonals-square-matrix/) 給定一個方陣,找出在同一行中以及在主和次對角線上都相同的數字計數。 **示例**: ``` Input : 1 2 1 4 5 2 0 5 1 Output : 2 Primary diagonal is 1 5 1 Secondary diagonal is 1 5 0 Two elements (1 and 5) match in two diagonals and same. Input : 1 0 0 0 1 0 0 0 1 Output : 1 Primary diagonal is 1 1 1 Secondary diagonal is 0 1 0 Only one element is same. ``` 我們可以在`O(n)`時間,`O(1)`空間和僅一個遍歷中實現這一目標。 我們可以在主對角線的第 i 行找到當前元素作為 mat [i] [i],在次對角線的第 i 個元素找到作為 mat [i] [n-i-1]。 ## C++ ```cpp // CPP program to find common elements in // two diagonals. #include <iostream> #define MAX 100 using namespace std; // Returns count of row wise same // elements in two diagonals of // mat[n][n] int countCommon(int mat[][MAX], int n) { ????int res = 0; ????for (int i=0;i<n;i++) ????????if (mat[i][i] == mat[i][n-i-1]) ?????????????res++; ????return res; } // Driver Code int main() { ????int mat[][MAX] = {{1, 2, 3},? ??????????????????????{4, 5, 6}, ??????????????????????{7, 8, 9}}; ????cout << countCommon(mat, 3); ????return 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>

                              哎呀哎呀视频在线观看