Problem 109. Check if sorted
Check if sorted.
Example:
Input x = [1 2 0] Output y is 0
Solution Stats
Problem Comments
-
10 Comments
Sort means ascending or descending or both? Not clear
I agree! The code is significantly different for those possible cases.
Unfortunately, way too easy!
I agree it's not clear ... but
y = ~var(nonzeros(sign(diff(x))));
works for both ascending/descending cases.
(The test suite clarifies that ascending is the intended case)
y = ~var(nonzeros(sign(diff(x)))); amazing~ !nice idea
There is a sort array command in MATLAB.
if you are not familiar with array, will be difficult
nice
hehe
The solution "y = issorted(x);" with a metric of 12 is not the leading solution. "Fair Play" is something unknown to cheaters!
Solution Comments
Show commentsProblem Recent Solvers4391
Suggested Problems
-
given 3 sides, find area of this triangle
797 Solvers
-
07 - Common functions and indexing 6
451 Solvers
-
Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
941 Solvers
-
6183 Solvers
-
Find the max element of the array
1525 Solvers
More from this Author100
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!