Check if Array is Sorted and Rotated

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
357 B
0
Indexable
Never
class Solution {
public:
    bool check(vector<int>& nums) {
        int count = 0;
        int n = nums.size();

        for(int i = 1; i< n; i++){
            if(nums[i - 1]> nums[i]){
                count++;
            }
        }

        if(nums[n - 1]> nums[0]){
            count++;
        }

        return count <= 1 ;
    }
};
Leave a Comment