Skip to content

Commit 991786f

Browse files
authored
Added Check if Array Is Sorted and Rotated.java
1 parent 6b9256d commit 991786f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public boolean check(int[] nums) {
3+
boolean rotationFound = false;
4+
for (int i = 0; i < nums.length - 1; i++) {
5+
if (nums[i] > nums[i + 1]) {
6+
if (rotationFound) {
7+
return false;
8+
}
9+
rotationFound = true;
10+
}
11+
}
12+
if (rotationFound && nums[nums.length - 1] > nums[0]) {
13+
return false;
14+
}
15+
return true;
16+
}
17+
}

0 commit comments

Comments
 (0)