Skip to content

Commit 60e692c

Browse files
Add files via upload
1 parent 8387448 commit 60e692c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import string
2+
3+
def monotonicArray(array):
4+
if(len(array) <= 2):
5+
return True
6+
isIncrease = True
7+
isDecrease = True
8+
p0 = 1
9+
p1 = 0
10+
for i in range(1, len(array)):
11+
12+
if(array[p0] < array[p1]):
13+
isIncrease = False
14+
elif(array[p0] > array[p1]):
15+
isDecrease = False
16+
p0 += 1
17+
p1 += 1
18+
19+
return (isIncrease or isDecrease)
20+
21+
22+
array = [1,2,2,3]
23+
print(monotonicArray(array))
24+
25+
26+
array = [2, 1, 0, -1, 3]
27+
print(monotonicArray(array))

0 commit comments

Comments
 (0)