<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/find-rotation-count-rotated-sorted-array/](https://www.geeksforgeeks.org/find-rotation-count-rotated-sorted-array/) 考慮以遞增順序排序的一組不同數字。 數組(順時針)旋轉了 k 次。 給定這樣一個數組,找到 k 的值。 **示例**: ``` Input : arr[] = {15, 18, 2, 3, 6, 12} Output: 2 Explanation : Initial array must be {2, 3, 6, 12, 15, 18}. We get the given array after rotating the initial array twice. Input : arr[] = {7, 9, 11, 12, 5} Output: 4 Input: arr[] = {7, 9, 11, 12, 15}; Output: 0 ``` **方法 1(使用[線性搜索](http://quiz.geeksforgeeks.org/linear-search/))** 如果仔細研究示例,我們會發現轉數等于最小元素的索引。 一個簡單的線性解決方案是找到最小元素并返回其索引。 以下是該想法的 C++ 實現。 ## C++ ```cpp // C++ program to find number of rotations // in a sorted and rotated array. #include<bits/stdc++.h> using namespace std; // Returns count of rotations for an array which // is first sorted in ascending order, then rotated int countRotations(int arr[], int n) { ????// We basically find index of minimum ????// element ????int min = arr[0], min_index; ????for (int i=0; i<n; i++) ????{ ????????if (min > arr[i]) ????????{ ????????????min = arr[i]; ????????????min_index = i; ????????} ????} ????return min_index; } // Driver code int main() { ????int arr[] = {15, 18, 2, 3, 6, 12}; ????int n = sizeof(arr)/sizeof(arr[0]); ????cout << countRotations(arr, n); ????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>

                              哎呀哎呀视频在线观看