Golang Leetcode 868. Binary Gap.go
2019-04-26 23:08
281 查看
版权声明:原创勿转 https://blog.csdn.net/anakinsun/article/details/89578355
思路
N不断的右移,同时判断是否等于1
code
func binaryGap(N int) int { var d, max int if N&(N-1) == 0 { return 0 } for ; N > 0; N >>= 1 { //N不断的右移 if N&1 == 1 { //判断是否等于1 if max == 0 { max = 1 } if d > max { max = d } d = 0 } if max > 0 { d++ } } return max }
更多内容请移步我的repo:https://github.com/anakin/golang-leetcode
相关文章推荐
- Golang Leetcode 123. Best Time to Buy and Sell Stock III.go
- Golang Leetcode 445. Add Two Numbers II.go
- Golang Leetcode 131. Palindrome Partitioning.go
- Golang Leetcode 142. Linked List Cycle II.go
- Golang Leetcode 173. Binary Search Tree Iterator.go
- Leetcode 709. 转换成小写字母 golang go 语言
- Golang Leetcode 260. Single Number III.go
- go/golang 中的import
- GO_05_2:Golang 中 panic、recover、defer 的用法
- 初探go-golang语言初体验
- 【GO语言学习】LeetCode74. 搜索二维矩阵---二分法
- Golang横空出世的背景(为什么选择Go)
- Golang(Go语言)读取文件基本用法
- golang 跨平台编译——go 在windows上编译Linux平台的程序(Cross Compilation from Windows to Linux/Ubuntu)
- 算法代码实现之冒泡排序,Golang(Go语言)实现
- 【GOLANG】Go语言学习-select用法
- golang 走起(九) linux 下 go语言 vim设置
- 在 go/golang语言中使用 google Protocol Buffer
- Golang(Go 语言)入门学习-5-映射
- Go实战--golang中使用图片和验证码(dchest/captcha)