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/Dynamic_Programming/487.Max-Consecutive-Ones-II at master · wisdompeak/LeetCode

Expand file tree

/

487.Max-Consecutive-Ones-II

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

487.Max-Consecutive-Ones-II

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
487.Max-Consecutive-Ones-II.cpp
487.Max-Consecutive-Ones-II.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

487.Max Consecutive Ones II  

类似于动态规划的思想,设计两个状态变量: count1记录当前从未使用反转权力、可以得到的连续1的个数;count2记录当前已经使用反转权力、可以得到的连续1的个数。

如果nums[i]==1,那么count1和count2各自加1,没有问题。

如果nums[i]==0,那么count1要置零;count2怎么办呢?事实上count2=count1+1既可。

一路上追踪最大曾出现过的count2就是最后的答案。

Leetcode Link

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.