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 1f30aec commit b18701dCopy full SHA for b18701d
001-500/446.py
@@ -0,0 +1,15 @@
1
+class Solution:
2
+ def numberOfArithmeticSlices(self, nums: List[int]) -> int:
3
+ n = len(nums)
4
+ total_count = 0
5
+ dp = [defaultdict(int) for _ in range(n)]
6
+
7
+ for i in range(1, n):
8
+ for j in range(i):
9
+ diff = nums[i] - nums[j]
10
+ dp[i][diff] += 1
11
+ if diff in dp[j]:
12
+ dp[i][diff] += dp[j][diff]
13
+ total_count += dp[j][diff]
14
15
+ return total_count
0 commit comments