Solution/MATLAB

[Cody] Problem 128. Sorted highest to lowest?

2023. 8. 22. 23:00

Return 1 if the input is sorted from highest to lowest, 0 if not.

Example:

1:7     -> 0
[7 5 2] -> 1

function y = your_fcn_name(x)

  des_x = sort(x, 'descend')
  
  if isequal(x, des_x)
    y = 1
  else
    y = 0
  end
end
댓글수0