mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
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:
parent
ace1c69509
commit
dee9ac73cd
@ -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
18
leetcode/src/1752.c
Normal 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];
|
||||
}
|
Loading…
Reference in New Issue
Block a user