Skip to content

Commit 24e026d

Browse files
Merge pull request #63 from imGaneshS/patch-1
Solution for AP Problem in Leetcode
2 parents 6cb7f79 + f1a9c8f commit 24e026d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

arithmeticProgression.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/
2+
3+
class arithmeticProgression {
4+
public boolean canMakeArithmeticProgression(int[] arr) {
5+
Arrays.sort(arr);
6+
int difference = arr[1] - arr[0];
7+
for (int i = 2 ; i <= arr.length - 1 ; i++) {
8+
if ((arr[i] - arr[i - 1]) != difference)
9+
return false;
10+
}
11+
return true;
12+
}
13+
}

0 commit comments

Comments
 (0)