We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个列表和滑动窗口的大小,找出所有滑动窗口里数值的最大值。
例如:如果输入列表[2,3,4,2,6,2,5,1]及滑动窗口的大小3,那么一共存在6个滑 动窗口,他们的最大值分别为[4,4,6,6,6,5]; 针对列表[2,3,4,2,6,2,5,1]的滑动 窗口有以下6个: [[2,3,4],2,6,2,5,1], [2,[3,4,2],6,2,5,1], [2,3,[4,2,6],2,5,1], [2,3,4,[2,6,2],5,1], [2,3,4,2,[6,2,5],1], [2,3,4,2,6,[2,5,1]]。
def maxInWindows(num,size): if size <= 0 or len(num) < size: return [] length = len(num) result = [] for i in range(0,length - size + 1): result.append(max(num[i:i+size])) return result print(maxInWindows([2,3,4,2,6,2,5,1],3)) ## [4, 4, 6, 6, 6, 5]
对滑窗内每个数字都进行扫描,直到找到和最大值相等数字,相等表明我的一个滑窗扫描结束,进入下一个滑窗进行扫描,并取最大值。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给定一个列表和滑动窗口的大小,找出所有滑动窗口里数值的最大值。
例如:如果输入列表[2,3,4,2,6,2,5,1]及滑动窗口的大小3,那么一共存在6个滑
动窗口,他们的最大值分别为[4,4,6,6,6,5]; 针对列表[2,3,4,2,6,2,5,1]的滑动
窗口有以下6个: [[2,3,4],2,6,2,5,1], [2,[3,4,2],6,2,5,1], [2,3,[4,2,6],2,5,1],
[2,3,4,[2,6,2],5,1], [2,3,4,2,[6,2,5],1], [2,3,4,2,6,[2,5,1]]。
对滑窗内每个数字都进行扫描,直到找到和最大值相等数字,相等表明我的一个滑窗扫描结束,进入下一个滑窗进行扫描,并取最大值。
The text was updated successfully, but these errors were encountered: