GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update 027.cpp · hfl15/algorithm@3a7be26

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • sword_offer/src
    • 027.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎sword_offer/src/027.cpp‎

Copy file name to clipboardExpand all lines: sword_offer/src/027.cpp
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
1212
[解析]
1313
方法 1:
14-
以窗口在数组上滑动,没次都重新计算窗口中最大值,那么总的时间复杂度为 O(n*size),当窗口大小 size 很大时,不可取。
14+
以窗口在数组上滑动,每次都重新计算窗口中最大值,那么总的时间复杂度为 O(n*size),当窗口大小 size 很大时,不可取。
1515
方法 2:
1616
以空间换时间,使用一个双端队列,使得每次获取最大值的操作可以在 O(1) 的时间内完成。
17-
队列的前边存储当前最大值在数组中对应的下标,而其后存储的时有可能成为新的最大值的候选。
17+
队列的前边存储当前最大值在数组中对应的下标,而其后存储的是有可能成为新的最大值的候选。
1818
每次循环需要做两件事情:(1)检查当前最大值是否过期,若过期则弹出最前面的元素;
19-
(2)更新最大值的候选,从后往前检查将对列中小于当前值的所有元素弹出;
20-
完成以上两个操作以后奖当前元素插入到队列的最后成为候选。
19+
(2)更新最大值的候选,从后往前检查将队列中小于当前值的所有元素弹出;
20+
完成以上两个操作以后将当前元素插入到队列的最后成为候选。
2121
*/
2222

2323

@@ -59,4 +59,4 @@ class Solution{
5959
int main()
6060
{
6161
return 0;
62-
}
62+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.