Skip to content

Commit c8332b2

Browse files
Add CheckIfArrayIsRotatedAndSorted class
1 parent bbe6889 commit c8332b2

File tree

1 file changed

+18
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)