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 — LeetCode/Greedy/1535.Find-the-Winner-of-an-Array-Game at master · wisdompeak/LeetCode

Expand file tree

/

1535.Find-the-Winner-of-an-Array-Game

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

1535.Find-the-Winner-of-an-Array-Game

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
1535.Find-the-Winner-of-an-Array-Game.cpp
1535.Find-the-Winner-of-an-Array-Game.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

1535.Find-the-Winner-of-an-Array-Game

本题模拟一个“打擂台”的机制。对于一个数A,如果它连续大于之后的K个数,那么它是winner。

如果数A在成为winner之前被数B压过,那么数A(以及被数A击败的数)是否要append到arr末尾来继续参与这场模拟呢?不需要。事实上没必要在考察完n个数之后继续模拟来找winner。因为我们在第一轮遍历这n个数的时候,必然会遇到一个全局的最大值Max,它之后的所有数(以及包括额外append到数组末尾的数)都不可能击败它。所以如果我们考察完n个数之后还没有确定winner,那么手头的最大值(就是全局最大值)就一定是winner,因为它一定会击败所有元素。

因此,我们只需要从头开始,模拟类似“打擂台”的机制,只要某个数连胜K场,就是winner。否则考察完n个数,手头的最大值(就是全局最大值)就是winner。

另外,如果K大于n的话,说明winner要击败所有元素(好几圈),那么同样说明winner一定就是全局最大值。

You are visitor 01402809 — 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.