Determine If an Array Is Already Sorted
Implement isSorted
Given an array of integers
nums, determine whether it is sorted in non-decreasing order — meaning every element is greater than or equal to the one before it.
You don't need to sort the array or return anything about *how* it's ordered — just answer true or false. Equal neighbouring values are allowed; only a strictly-smaller element right after a bigger one breaks the order.
Example 1:
Input: nums = [2,4,6,6,9,15]
Output: true
Example 2:
Input: nums = [8,3,12]
Output: false
Example 3:
Input: nums = [7,7,7,7]
Output: true
+ 7 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ nums.length ≤ 10⁵ - ●
-10⁹ ≤ nums[i] ≤ 10⁹
nums =
[2, 4, 6, 6, 9, 15]