Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

239 Sliding Window Maximum Python Solution #1015

Closed
@bcatalfo

Description

@bcatalfo

InNeetCode's video solution he only uses one deque to keep track of the indexes but inthe python solution here two deques are used, one keeping track of the index and the other keeping track of the value. Additionally you unnecessarily changed a while statement to an if statement. I made some changes to make the solution closer to the solution presented in the video as well as more efficient and readable

classSolution:defmaxSlidingWindow(self,nums:List[int],k:int)->List[int]:index_q=deque()res= []fori,ninenumerate(nums):whileindex_qandn>nums[index_q[-1]]:index_q.pop()index_q.append(i)ifindex_q[0]==i-k:index_q.popleft()ifi+1>=k:res.append(nums[index_q[0]])returnres

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp