You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/com/fishercoder/solutions/_413.java
+28-22Lines changed: 28 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,16 @@
1
1
packagecom.fishercoder.solutions;
2
2
3
-
/**A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
3
+
/**
4
+
* 413. Arithmetic Slices
5
+
*
6
+
* A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
4
7
5
8
For example, these are arithmetic sequence:
6
9
7
10
1, 3, 5, 7, 9
8
11
7, 7, 7, 7
9
12
3, -1, -5, -9
13
+
10
14
The following sequence is not arithmetic.
11
15
12
16
1, 1, 2, 5, 7
@@ -18,40 +22,42 @@ A slice (P, Q) of array A is called arithmetic if the sequence:
18
22
19
23
The function should return the number of arithmetic slices in the array A.
20
24
21
-
22
25
Example:
23
26
24
27
A = [1, 2, 3, 4]
25
28
26
-
return: 3, for 3 arithmetic slices in A: [1, 2, 3], [2, 3, 4] and [1, 2, 3, 4] itself.*/
29
+
return: 3, for 3 arithmetic slices in A: [1, 2, 3], [2, 3, 4] and [1, 2, 3, 4] itself.
30
+
*/
27
31
publicclass_413 {
28
32
29
-
//copied this solution: https://discuss.leetcode.com/topic/62884/2ms-java-o-n-time-o-1-space-solution