mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-02-12 21:39:06 +00:00
* add Check if Array Is Sorted and Rotated * Update 1752.c add new line * Rename README.md to DIRECTORY.md Co-authored-by: David Leal <halfpacho@gmail.com>
19 lines
406 B
C
19 lines
406 B
C
bool check(int* nums, int numsSize){
|
|
if (numsSize == 1) {
|
|
return true;
|
|
}
|
|
|
|
bool wasShift = false;
|
|
for(int i = 1; i < numsSize; i++) {
|
|
if (nums[i - 1] > nums[i]) {
|
|
if (wasShift) {
|
|
return false;
|
|
}
|
|
|
|
wasShift = true;
|
|
}
|
|
}
|
|
|
|
return !wasShift || nums[0] >= nums[numsSize-1];
|
|
}
|