2024-07-06发表2025-01-15更新LeetCode每日一题几秒读完 (大约74个字)0次访问3101. 交替子数组计数交替子数组计数 难度: medium 原始链接: https://leetcode.cn/problems/count-alternating-subarrays 标签: 双指针 解法一: 双指针go123456789101112131415func countAlternatingSubarrays(nums []int) int64 { n := len(nums) ans := int64(n) i := 0 j := 1 for j < n { if nums[j] != nums[j-1] { ans += int64(j - i) } else { i = j } j++ } return ans} 3101. 交替子数组计数https://wuhunyu.top/leetcode/2024/07/count-alternating-subarrays/index.html作者wuhunyu发布于2024-07-06更新于2025-01-15许可协议#双指针