Skip to content

Commit 2f8ce59

Browse files
authored
Create Solution2.js
1 parent 15492af commit 2f8ce59

File tree

1 file changed

+17
-0
lines changed
  • solution/1500-1599/1502.Can Make Arithmetic Progression From Sequence

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[]} arr
3+
* @return {boolean}
4+
*/
5+
var canMakeArithmeticProgression = function(arr) {
6+
arr.sort((a,b)=>a-b)
7+
8+
let val = arr[1] - arr [0]
9+
10+
for(let i = 1 ; i < arr.length-1 ; i++){
11+
if(arr[i+1]-arr[i] !== val){
12+
return false
13+
}
14+
}
15+
16+
return true
17+
};

0 commit comments

Comments
 (0)