Check array sorted (non-decreasing)
Java
Easy
5 views
Problem Description
Task: return true if the array is sorted in non-decreasing order. Compare adjacent elements.
Output Format
Return value
Constraints
Empty or single element is sorted.
Official Solution
static boolean isSorted(int[] a){for(int i=1;i<a.length;i++) if(a[i]<a[i-1]) return false;return true;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!