Class Solution

java.lang.Object
g0801_0900.s0896_monotonic_array.Solution

public class Solution extends Object
896 - Monotonic Array.<p>Easy</p> <p>An array is <strong>monotonic</strong> if it is either monotone increasing or monotone decreasing.</p> <p>An array <code>nums</code> is monotone increasing if for all <code>i <= j</code>, <code>nums[i] <= nums[j]</code>. An array <code>nums</code> is monotone decreasing if for all <code>i <= j</code>, <code>nums[i] >= nums[j]</code>.</p> <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if the given array is monotonic, or</em> <code>false</code> <em>otherwise</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,2,2,3]</p> <p><strong>Output:</strong> true</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [6,5,4,4]</p> <p><strong>Output:</strong> true</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [1,3,2]</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isMonotonic

      public boolean isMonotonic(int[] nums)