Skip to content

Commit c60e6f2

Browse files
authored
Create sourcema.md
1 parent 89425c3 commit c60e6f2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

2019.02.01-leetcode413/sourcema.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# leetcode 413
2+
class Solution {
3+
public int numberOfArithmeticSlices(int[] A) {
4+
if(A==null||A.length==0){
5+
return 0;
6+
}
7+
int res=0;
8+
for(int i=0;i<A.length;i++){
9+
for(int j=i+1;j<A.length;j++){
10+
if(j-i>=2&&isArithmetic(A,i,j)){
11+
res+=1;
12+
}
13+
}
14+
}
15+
return res;
16+
}
17+
public boolean isArithmetic(int[] arr,int i,int j){
18+
int d=arr[i+1]-arr[i];
19+
for(int k=i+1;k<j;k++){
20+
if(arr[k+1]-arr[k]!=d){
21+
return false;
22+
}
23+
}
24+
return true;
25+
}
26+
}

0 commit comments

Comments
 (0)