goden0503

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 0 Imported by: 0

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

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL