Last active
June 29, 2021 06:06
-
-
Save blacksheep557/cbb38123614e2eb489ee65437cd473d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def arithematic_subarray(array): | |
| if len(array) < 3: | |
| return 0 | |
| iteration_count = 1 | |
| difference = array[1] - array[0] | |
| res = 0 | |
| for i in range(2, len(array)): | |
| diff = array[i] - array[i-1] | |
| if diff == difference: | |
| iteration_count += 1 | |
| else: | |
| difference = diff | |
| iteration_count = 1 | |
| if iteration_count is 2: | |
| res += 1 | |
| print(array[i-2:i+1]) | |
| elif iteration_count > 2: | |
| res += 1 + (iteration_count - 2) | |
| return res | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment