674、697,717,724,746,747,766
674:最长连续递增序列
题目描述:
给定一个未经排序的整数数组,找到最长且连续的的递增序列。
思路:
遍历并比较长度。
代码:
class Solution(object):
def findLengthOfLCIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums)<2:
return len(nums)
else:
count=1
max1=1
for i in range(len(nums)-1):
if nums[i]<nums[i+1]:
count+=1
else:
max1=max(max1,count)
count=1
return max(max1,count)
697:数组的度
题目描述:
给定一个非空且只包含非负数的整数数组 nums, 数组的度的定义是指数组里任一元素出现频数的最大值。你的任务是找到与 nums 拥有相同大小的度的最短连续子数组,返回其长度。
思路:
1、用字典记录每个数的频数,每个数对应的索引范围 , a[nums[i]]=[1,i,i]
2、遍历字典找出频数最大的数,并记录索引范围,若出现频数相同,比较索引范围,得出较小的索引范围即可。
代码:
class Solution(object):
def findShortestSubArray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
a=dict()
for i in range(len(nums)):
if nums[i] not in a:
a[nums[i]]=