MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / is_monotonic

Function is_monotonic

896-monotonic-array.rs:1–10  ·  view source on GitHub ↗
(nums: Vec<i32>)

Source from the content-addressed store, hash-verified

1pub fn is_monotonic(nums: Vec<i32>) -> bool {
2 let mut sorted_nums = nums.clone();
3 sorted_nums.sort();
4 if nums == sorted_nums {
5 true
6 } else {
7 sorted_nums.reverse();
8 nums == sorted_nums
9 }
10}
11
12fn main() {
13 let nums = vec![1,2,2,3];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected