Skip to content

Commit a54bdf6

Browse files
committedJul 5, 2020
add 1502
1 parent 330174d commit a54bdf6

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1502|[Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1502.java) | |Easy|Array, Sort|
1112
|1496|[Path Crossing](https://leetcode.com/problems/path-crossing/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1496.java) | |Easy|String|
1213
|1493|[Longest Subarray of 1's After Deleting One Element](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1493.java) | |Medium|Array|
1314
|1492|[The kth Factor of n](https://leetcode.com/problems/the-kth-factor-of-n/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1492.java) | |Medium|Math|
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _1502 {
6+
public static class Solution1 {
7+
public boolean canMakeArithmeticProgression(int[] arr) {
8+
Arrays.sort(arr);
9+
for (int i = 0; i < arr.length - 2; i++) {
10+
if (arr[i + 1] - arr[i] != arr[i + 2] - arr[i + 1]) {
11+
return false;
12+
}
13+
}
14+
return true;
15+
}
16+
}
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1502;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1502Test {
10+
private static _1502.Solution1 solution1;
11+
private static int[] arr;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1502.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
arr = new int[]{3, 5, 1};
21+
assertEquals(true, solution1.canMakeArithmeticProgression(arr));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)
Please sign in to comment.