Created
November 22, 2025 20:02
-
-
Save shunting314/6e3553970548259a60cabb316709f350 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
| class Solution { | |
| public: | |
| int numberOfArithmeticSlices(vector<int>& nums) { | |
| int out = 0; | |
| int s = 0; | |
| while (s + 1 < nums.size()) { | |
| int dif = nums[s + 1] - nums[s]; | |
| int e = s + 2; | |
| while (e < nums.size() && nums[e] - nums[e - 1] == dif) { | |
| ++e; | |
| } | |
| int len = e - s; | |
| // count | |
| out += (len - 2) * (len - 1) / 2; | |
| s = e - 1; | |
| } | |
| return out; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment