标签:双指针 art 贪心 block 长度 mat tar 贪心算法 算法
给定一个未经排序的整数数组,找到最长且连续递增的子序列,并返回该序列的长度。
如:
[1,2,3,2,3,4,3,4,5,6,7]
返回5.
func findLength(nums []int)int{
var start = 0
var maxLength = 0
for i:=1;i<len(nums);i++{
if nums[i]<=nums[i-1]{
start = i
}
maxLength = int(math.Max(float64(maxLength),
float64(i-start+1)))
}
return maxLength
}
func findLength2(nums []int)int{
var low = 0
var high = 1
var n = len(nums)
var maxLength = 0
for low<n && high<n{
if nums[high]<=nums[high-1]{
low = high
}
maxLength = int(math.Max(float64(high-low+1),
float64(maxLength)))
high++
}
return maxLength
}
标签:双指针 art 贪心 block 长度 mat tar 贪心算法 算法
原文地址:https://www.cnblogs.com/pangqianjin/p/14631599.html