mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-03 22:41:58 +00:00
添加Go语言题解
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
|
||||
下面我们通过一个视频模拟代码执行步骤大家一下就能搞懂了。
|
||||
|
||||

|
||||

|
||||
|
||||
下面我们直接看代码吧
|
||||
|
||||
@@ -207,3 +207,28 @@ public:
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Go Code:
|
||||
|
||||
```go
|
||||
func findMaxConsecutiveOnes(nums []int) int {
|
||||
cnt, maxCnt := 0, 0
|
||||
for i := 0; i < len(nums); i++ {
|
||||
if nums[i] == 1 {
|
||||
cnt++
|
||||
} else {
|
||||
maxCnt = max(maxCnt, cnt)
|
||||
cnt = 0
|
||||
}
|
||||
}
|
||||
return max(maxCnt, cnt)
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user