<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/roof-top/](https://www.geeksforgeeks.org/roof-top/) 給定連續建筑物的高度,找到一個人可以提出的最大連續臺階數,這樣他從一棟建筑物的屋頂轉到下一棟相鄰建筑物的屋頂時,高度會增加。 **示例**: ``` Input : arr[] = {1, 2, 2, 3, 2} Output : 1 Explanation : Maximum consecutive steps from 1 to 2 OR 2 to 3. Input : arr[] = {1, 2, 3, 4} Output : 3 ``` ![](https://img.kancloud.cn/ab/3c/ab3c4df5dbfc33eac9d2e9be283fd5c1_523x284.png) 此問題基本上是[最長遞增子數組](https://www.geeksforgeeks.org/longest-increasing-subarray/)的變體 方法: ``` initialize count = 0 initialize maximum = 0 if arr[i]>a[i-1] then count increment else maximum = max(maximum, count) at the end maximum=max(maximum, count) ``` ## C++ ```cpp // CPP code to find maximum? // number of consecutive steps. #include <bits/stdc++.h> using namespace std; // Function to count consecutive steps int find_consecutive_steps(int arr[], int len) { ????int count = 0; ????int maximum = 0; ????for (int index = 1; index < len; index++) { ????????// count the number of consecutive? ????????// increasing height building ????????if (arr[index] > arr[index - 1]) ????????????count++; ????????else ????????{ ????????????maximum = max(maximum, count); ????????????count = 0; ????????} ????} ????return max(maximum, count);???? } // Driver code int main() { ????int arr[] = { 1, 2, 3, 4 }; ????int len = sizeof(arr) / sizeof(arr[0]); ????cout << find_consecutive_steps(arr, len); } ``` ## Java ```java // Java code to find maximum? // number of consecutive steps. import java.io.*; class GFG { ????// Function to count consecutive steps ????static int find_consecutive_steps(int arr[], ????????????????????????????????????????int len) ????{ ????????int count = 0; ????????int maximum = 0; ????????for (int index = 1; index < len; index++) { ????????????// count the number of consecutive? ????????????// increasing height building ????????????if (arr[index] > arr[index - 1]) ????????????????count++; ????????????else ????????????{ ????????????????maximum = Math.max(maximum, count); ????????????????count = 0; ????????????} ????????} ????????return Math.max(maximum, count);? ????} ????// Driver code ????public static void main (String[] args) { ????????int arr[] = { 1, 2, 3, 4 }; ????????int len = arr.length; ????????System.out.println(find_consecutive_steps(arr, ????????????????????????????????????????????????len)); ????} } // This code is contributed by Gitanjali. ``` ## Python3 ```py # Python3 code to find maximum? # number of consecutive steps import math # Function to count consecutive steps def find_consecutive_steps(arr, len): ????count = 0; maximum = 0 ????for index in range(1, len): ????????# count the number of consecutive? ????????# increasing height building ????????if (arr[index] > arr[index - 1]): ????????????count += 1 ????????else: ????????????maximum = max(maximum, count) ????????????count = 0 ????return max(maximum, count) # Driver code arr = [ 1, 2, 3, 4 ] len = len(arr) print(find_consecutive_steps(arr, len)) # This code is contributed by Gitanjali. ``` ## C# ```cs // C# code to find maximum? // number of consecutive steps. using System; class GFG { ????// Function to count consecutive steps ????static int find_consecutive_steps(int []arr, ????????????????????????????????????????int len) ????{ ????????int count = 0; ????????int maximum = 0; ????????for (int index = 1; index < len; index++) { ????????????// count the number of consecutive? ????????????// increasing height building ????????????if (arr[index] > arr[index - 1]) ????????????????count++; ????????????else ????????????{ ????????????????maximum = Math.Max(maximum, count); ????????????????count = 0; ????????????} ????????} ????????return Math.Max(maximum, count);? ????} ????// Driver code ????public static void Main () { ????????int []arr = { 1, 2, 3, 4 }; ????????int len = arr.Length; ????????Console.WriteLine(find_consecutive_steps(arr, ????????????????????????????????????????????????len)); ????} } // This code is contributed by vt_m. ``` ## PHP ```php <?php // PHP code to find maximum? // number of consecutive steps. // Function to count // consecutive steps function find_consecutive_steps($arr,? ????????????????????????????????$len) { ????$count = 0; ????$maximum = 0; ????for ($index = 1; $index < $len;? ??????????????????????????$index++)? ????{ ????????// count the number of consecutive? ????????// increasing height building ????????if ($arr[$index] > $arr[$index - 1]) ????????????$count++; ????????else ????????{ ????????????$maximum = max($maximum, $count); ????????????$count = 0; ????????} ????} ????return max($maximum, $count);? } // Driver code $arr = array( 1, 2, 3, 4 ); $len = count($arr); echo find_consecutive_steps($arr, $len); // This code is contributed by vt_m.? ?> ``` **輸出**: ``` 3 ``` * * * * * *
                  <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>

                              哎呀哎呀视频在线观看