We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ca8b094 commit 22051eaCopy full SHA for 22051ea
0446-arithmetic-slices-ii-subsequence/0446-arithmetic-slices-ii-subsequence.py
@@ -0,0 +1,24 @@
1
+from collections import defaultdict
2
+from typing import List
3
+
4
5
+class Solution:
6
+ def numberOfArithmeticSlices(self, nums: List[int]) -> int:
7
+ n = len(nums)
8
+ totalCount = 0
9
10
+ dp = [defaultdict(int) for _ in range(n)]
11
12
+ for i in range(1, n):
13
+ for j in range(i):
14
+ diff = nums[i] - nums[j]
15
16
+ if diff < -2**31 or diff > 2**31 - 1:
17
+ continue
18
19
+ count = dp[j][diff] if diff in dp[j] else 0
20
21
+ totalCount += count
22
+ dp[i][diff] += count + 1
23
24
+ return totalCount
0 commit comments