Skip to content

Commit 04d5d69

Browse files
solves check if array is sorted and rotated
1 parent 92f7dfb commit 04d5d69

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LeetCode Algorithms
22

3-
![problems-solved](https://img.shields.io/badge/Problems%20Solved-328/2081-1f425f.svg)
4-
![problems-solved-java](https://img.shields.io/badge/Java-328/2081-1abc9c.svg)
3+
![problems-solved](https://img.shields.io/badge/Problems%20Solved-352/2081-1f425f.svg)
4+
![problems-solved-java](https://img.shields.io/badge/Java-352/2081-1abc9c.svg)
55
![problems-solved-python](https://img.shields.io/badge/Python-186/2081-1abc9c.svg)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
77
[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming)
@@ -427,8 +427,8 @@
427427
| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | [![Java](assets/java.png)](src/FindTheHighestAltitude.java) | |
428428
| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | [![Java](assets/java.png)](src/LatestTimeByReplacingHiddenDigits.java) | |
429429
| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | [![Java](assets/java.png)](src/MaximumNumberOfBallsInABox.java) | |
430-
| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | [![Java](assets/java.png)](src/SumOfUniqueElements.java) | |
431-
| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | | |
430+
| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | [![Java](assets/java.png)](src/SumOfUniqueElements.java) | |
431+
| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [![Java](assets/java.png)](src/CheckIfArrayIsSortedAndRotated.java) | |
432432
| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | | |
433433
| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | | |
434434
| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | | |

Diff for: src/CheckIfArrayIsSortedAndRotated.java

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class CheckIfArrayIsSortedAndRotated {
2+
public boolean check(int[] array) {
3+
int slope = 0;
4+
for (int index = 0 ; index < array.length - 1 ; index++) {
5+
if (array[index] > array[index + 1]) slope++;
6+
}
7+
return slope == 0 || (slope == 1 && array[array.length - 1] <= array[0]);
8+
}
9+
}

0 commit comments

Comments
 (0)