java.lang.Object
g1901_2000.s1936_add_minimum_number_of_rungs.Solution

public class Solution extends Object
1936 - Add Minimum Number of Rungs.<p>Medium</p> <p>You are given a <strong>strictly increasing</strong> integer array <code>rungs</code> that represents the <strong>height</strong> of rungs on a ladder. You are currently on the <strong>floor</strong> at height <code>0</code>, and you want to reach the last rung.</p> <p>You are also given an integer <code>dist</code>. You can only climb to the next highest rung if the distance between where you are currently at (the floor or on a rung) and the next rung is <strong>at most</strong> <code>dist</code>. You are able to insert rungs at any positive <strong>integer</strong> height if a rung is not already there.</p> <p>Return <em>the <strong>minimum</strong> number of rungs that must be added to the ladder in order for you to climb to the last rung.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> rungs = [1,3,5,10], dist = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong></p> <p>You currently cannot reach the last rung.</p> <p>Add rungs at heights 7 and 8 to climb this ladder.</p> <p>The ladder will now have rungs at [1,3,5,7,8,10].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> rungs = [3,6,8,10], dist = 3</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> This ladder can be climbed without adding additional rungs.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> rungs = [3,4,6,7], dist = 2</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong></p> <p>You currently cannot reach the first rung from the ground.</p> <p>Add a rung at height 1 to climb this ladder.</p> <p>The ladder will now have rungs at [1,3,4,6,7].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= rungs.length <= 10<sup>5</sup></code></li> <li><code>1 <= rungs[i] <= 10<sup>9</sup></code></li> <li><code>1 <= dist <= 10<sup>9</sup></code></li> <li><code>rungs</code> is <strong>strictly increasing</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • addRungs

      public int addRungs(int[] rungs, int dist)