Skip to content

Commit 4ccb5eb

Browse files
update 986
1 parent 434118e commit 4ccb5eb

File tree

2 files changed

+23
-19
lines changed
  • src
    • main/java/com/fishercoder/solutions/firstthousand
    • test/java/com/fishercoder/firstthousand

2 files changed

+23
-19
lines changed

src/main/java/com/fishercoder/solutions/firstthousand/_896.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@
22

33
public class _896 {
44
public static class Solution1 {
5-
public boolean isMonotonic(int[] A) {
5+
public boolean isMonotonic(int[] nums) {
66
int i = 0;
7-
for (; i < A.length - 1; i++) {
8-
if (A[i] <= A[i + 1]) {
9-
continue;
10-
} else {
7+
//check if it's increasing
8+
for (; i < nums.length - 1; i++) {
9+
if (nums[i] > nums[i + 1]) {
1110
break;
1211
}
1312
}
14-
if (i == A.length - 1) {
13+
if (i == nums.length - 1) {
1514
return true;
1615
}
1716
i = 0;
18-
for (; i < A.length - 1; i++) {
19-
if (A[i] >= A[i + 1]) {
20-
continue;
21-
} else {
17+
//check if it's decreasing
18+
for (; i < nums.length - 1; i++) {
19+
if (nums[i] < nums[i + 1]) {
2220
break;
2321
}
2422
}
25-
return i == A.length - 1;
23+
return i == nums.length - 1;
2624
}
2725
}
2826
}
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
package com.fishercoder.firstthousand;
22

33
import com.fishercoder.solutions.firstthousand._896;
4-
import org.junit.BeforeClass;
5-
import org.junit.Test;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
66

7-
import static org.junit.Assert.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
88

99
public class _896Test {
1010
private static _896.Solution1 solution1;
11-
private static int[] A;
11+
private static int[] nums;
1212

13-
@BeforeClass
14-
public static void setup() {
13+
@BeforeEach
14+
public void setup() {
1515
solution1 = new _896.Solution1();
1616
}
1717

1818
@Test
1919
public void test1() {
20-
A = new int[]{1, 3, 2};
21-
assertEquals(false, solution1.isMonotonic(A));
20+
nums = new int[]{1, 3, 2};
21+
assertEquals(false, solution1.isMonotonic(nums));
22+
}
23+
24+
@Test
25+
public void test2() {
26+
nums = new int[]{6, 5, 4, 4};
27+
assertEquals(true, solution1.isMonotonic(nums));
2228
}
2329

2430
}

0 commit comments

Comments
 (0)