Class Solution

java.lang.Object
g0901_1000.s0962_maximum_width_ramp.Solution

public class Solution extends Object
962 - Maximum Width Ramp.<p>Medium</p> <p>A <strong>ramp</strong> in an integer array <code>nums</code> is a pair <code>(i, j)</code> for which <code>i < j</code> and <code>nums[i] <= nums[j]</code>. The <strong>width</strong> of such a ramp is <code>j - i</code>.</p> <p>Given an integer array <code>nums</code>, return <em>the maximum width of a <strong>ramp</strong> in</em> <code>nums</code>. If there is no <strong>ramp</strong> in <code>nums</code>, return <code>0</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [6,0,8,2,1,5]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The maximum width ramp is achieved at (i, j) = (1, 5): nums[1] = 0 and nums[5] = 5.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [9,8,1,0,1,9,4,0,4,1]</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong> The maximum width ramp is achieved at (i, j) = (2, 9): nums[2] = 1 and nums[9] = 1.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= nums.length <= 5 * 10<sup>4</sup></code></li> <li><code>0 <= nums[i] <= 5 * 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxWidthRamp

      public int maxWidthRamp(int[] nums)