Skip to content

Commit

Permalink
feat: add Check if Array Is Sorted and Rotated (TheAlgorithms#1141)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
alexpantyukhin and Panquesito7 authored Nov 18, 2022
1 parent ace1c69 commit dee9ac7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions leetcode/DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 18 additions & 0 deletions leetcode/src/1752.c
Original file line number Diff line number Diff line change
@@ -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];
}

0 comments on commit dee9ac7

Please sign in to comment.