原题链接:https://leetcode.cn/problems/check-if-it-is-possible-to-split-array/
一开始思路想错了。。导致浪费很多时间
其实只要能找到存在一个子数组,子数组长度为2,这个子数组符合条件就一定能拆分。。
func canSplitArray(nums []int, m int) bool {
n := len(nums)
if n <= 2 {
return true
}
for i, j := 0, 1; j < n; i, j = i + 1, j + 1 {
if nums[i] + nums[j] >= m {
return true
}
}
return false
}