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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 在給定的數組中找到一個固定點(等于索引的值) > 原文: [https://www.geeksforgeeks.org/find-a-fixed-point-in-a-given-array/](https://www.geeksforgeeks.org/find-a-fixed-point-in-a-given-array/) 給定一個由 n 個不同的整數組成的數組,這些數組按升序排序,如果數組中存在固定點,則編寫一個返回固定點的函數,否則返回-1。 數組中的不動點是索引 i,因此 arr [i]等于 i。 請注意,數組中的整數可以為負數。 例子: ``` Input: arr[] = {-10, -5, 0, 3, 7} Output: 3 // arr[3] == 3 Input: arr[] = {0, 2, 5, 8, 17} Output: 0 // arr[0] == 0 Input: arr[] = {-10, -5, 3, 4, 7, 9} Output: -1 // No Fixed Point ``` **方法 1(線性搜索)** 線性搜索索引 i,以使 arr [i] == i。 返回找到的第一個這樣的索引。 感謝 pm 建議這種解決方案。 ## C++ ```cpp // C++ program to check fixed point? // in an array using linear search? #include <bits/stdc++.h> using namespace std; int linearSearch(int arr[], int n)? {? ????int i;? ????for(i = 0; i < n; i++)? ????{? ????????if(arr[i] == i)? ????????????return i;? ????}? ????/* If no fixed point present then return -1 */ ????return -1;? }? /* Driver code */ int main()? {? ????int arr[] = {-10, -1, 0, 3, 10, 11, 30, 50, 100};? ????int n = sizeof(arr)/sizeof(arr[0]);? ????cout << "Fixed Point is " << linearSearch(arr, n);? ????return 0;? }? // This is code is contributed by rathbhupendra ```
                  <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>

                              哎呀哎呀视频在线观看