Skip to content

Commit

Permalink
Create 1752. Check if Array Is Sorted and Rotated (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Feb 2, 2025
2 parents 858ce27 + 869f7ed commit 052a8ce
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 1752. Check if Array Is Sorted and Rotated
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
bool check(vector<int>& nums) {
int n = nums.size();
int count = 0;

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

return count <= 1;
}
};

0 comments on commit 052a8ce

Please sign in to comment.