feat: add Check if Array Is Sorted and Rotated (#1141)

* 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>
This commit is contained in:
Alexander Pantyukhin 2022-11-19 00:02:59 +04:00 committed by GitHub
parent ace1c69509
commit dee9ac73cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -95,4 +95,5 @@
| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops/) | [C](./src/1184.c) | Easy |
| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/) | [C](./src/1189.c) | Easy |
| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | [C](./src/1207.c) | Easy |
| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/) | [C](./src/1752.c) | Easy |
| 2130 | [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/) | [C](./src/2130.c) | Medium |

18
leetcode/src/1752.c Normal file
View File

@ -0,0 +1,18 @@
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];
}