<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-the-maximum-element-in-an-array-which-is-first-increasing-and-then-decreasing/](https://www.geeksforgeeks.org/find-the-maximum-element-in-an-array-which-is-first-increasing-and-then-decreasing/) 給定一個整數數組,該數組最初是遞增的,然后遞減的,請在該數組中找到最大值。 **示例**: ``` Input: arr[] = {8, 10, 20, 80, 100, 200, 400, 500, 3, 2, 1} Output: 500 Input: arr[] = {1, 3, 50, 10, 9, 7, 6} Output: 50 Corner case (No decreasing part) Input: arr[] = {10, 20, 30, 40, 50} Output: 50 Corner case (No increasing part) Input: arr[] = {120, 100, 80, 20, 0} Output: 120 ``` **方法 1(線性搜索)** 我們可以遍歷數組并跟蹤最大值和元素。 最后返回最大元素。 ## C++ ```cpp // C++ program to find maximum? // element? #include <bits/stdc++.h> using namespace std; // function to find the maximum element? int findMaximum(int arr[], int low, int high)? {? ????int max = arr[low];? ????int i;? ????for (i = low + 1; i <= high; i++)? ????{? ????????if (arr[i] > max)? ????????????max = arr[i];? ????????// break when once an element is smaller than? ????????// the max then it will go on decreasing? ????????// and no need to check after that? ????????else ????????????break;? ????}? ????return max;? }? /* Driver code*/ int main()? {? ????int arr[] = {1, 30, 40, 50, 60, 70, 23, 20};? ????int n = sizeof(arr)/sizeof(arr[0]);? ????cout << "The maximum element is " << findMaximum(arr, 0, n-1);? ????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>

                              哎呀哎呀视频在线观看