-
Notifications
You must be signed in to change notification settings - Fork 0
/
2367-2.py
47 lines (37 loc) · 1.2 KB
/
2367-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from typing import List
import unittest
class Solution:
def arithmeticTriplets(self, nums: List[int], diff: int) -> int:
i, j, k = 0, 1, 2
size = len(nums) - 1
count = 0
while i <= size and j <= size and k <= size:
if nums[k] - nums[j] > diff:
j += 1
elif nums[k] - nums[j] < diff:
k += 1
else:
if nums[j] - nums[i] > diff:
i += 1
elif nums[j] - nums[i] < diff:
j += 1
else:
count += 1
j += 1
i += 1
return count
class Test(unittest.TestCase):
@unittest.skip(reason="just skip")
def test_first(self):
self.assertEqual(
Solution().arithmeticTriplets(nums=[0, 1, 4, 6, 7, 10], diff=3), 2
)
@unittest.skip(reason="just skip")
def test_second(self):
self.assertEqual(
Solution().arithmeticTriplets(nums=[4, 5, 6, 7, 8, 9], diff=2), 2
)
def test_third(self):
self.assertEqual(Solution().arithmeticTriplets(nums=[0, 1, 2], diff=0), 1)
if __name__ == '__main__':
unittest.main()