package
Version:
v0.0.0-...-b071cee
Opens a new window with list of versions in this module.
Published: Aug 9, 2023
License: GPL-3.0
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
面试题 05.03.翻转数位
1. 题目描述
给定一个32位整数 num ,你可以将一个数位从0变为1。请编写一个程序,找出你能够获得的最长的一串1的长度。
示例 1:
输入: num = 1775(110111011112)
输出: 8
示例 2:
输入: num = 7(01112)
输出: 4
标签
位运算 动态规划
2. 解题
每次维护三个变量
cur:当前位置为止连续1的个数,遇到0归零,遇到1加1
insert:在当前位置变成1,往前数连续1的最大个数,遇到0变为cur+1,遇到1加1
res:保存insert的最大值即可
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.