1752. Check if Array Is Sorted and Rotated Easy
1/**
2 * [1752] Check if Array Is Sorted and Rotated
3 *
4 * Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.
5 * There may be duplicates in the original array.
6 * Note: An array A rotated by x positions results in an array B of the same length such that A[i] == B[(i+x) % A.length], where % is the modulo operation.
7 *
8 * Example 1:
9 *
10 * Input: nums = [3,4,5,1,2]
11 * Output: true
12 * Explanation: [1,2,3,4,5] is the original sorted array.
13 * You can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].
14 *
15 * Example 2:
16 *
17 * Input: nums = [2,1,3,4]
18 * Output: false
19 * Explanation: There is no sorted array once rotated that can make nums.
20 *
21 * Example 3:
22 *
23 * Input: nums = [1,2,3]
24 * Output: true
25 * Explanation: [1,2,3] is the original sorted array.
26 * You can rotate the array by x = 0 positions (i.e. no rotation) to make nums.
27 *
28 *
29 * Constraints:
30 *
31 * 1 <= nums.length <= 100
32 * 1 <= nums[i] <= 100
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/
38// discuss: https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn check(nums: Vec<i32>) -> bool {
44 false
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_1752() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.