类似于动态规划的思想,设计两个状态变量: count1记录当前从未使用反转权力、可以得到的连续1的个数;count2记录当前已经使用反转权力、可以得到的连续1的个数。
如果nums[i]==1,那么count1和count2各自加1,没有问题。
如果nums[i]==0,那么count1要置零;count2怎么办呢?事实上count2=count1+1既可。
一路上追踪最大曾出现过的count2就是最后的答案。
GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — LeetCode/Dynamic_Programming/487.Max-Consecutive-Ones-II at master · wisdompeak/LeetCode Expand file tree/ Copy path487.Max-Consecutive-Ones-II/Directory actionsMore optionsMore optionsDirectory actionsMore optionsMore options/ Copy path487.Max-Consecutive-Ones-II/Folders and files
类似于动态规划的思想,设计两个状态变量: count1记录当前从未使用反转权力、可以得到的连续1的个数;count2记录当前已经使用反转权力、可以得到的连续1的个数。 如果nums[i]==1,那么count1和count2各自加1,没有问题。 如果nums[i]==0,那么count1要置零;count2怎么办呢?事实上count2=count1+1既可。 一路上追踪最大曾出现过的count2就是最后的答案。 | |||||||||||||||||||||
| 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. | |||||||||||||||||||||