/
githubmirror
/
LeetCode-Go
Обзор
Документация
Войти
/
githubmirror
/
LeetCode-Go
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
leetcode/0525.Contiguous-Array/525. Contiguous Array.go
27 строк
377 B
YDZ
Add solution 0097、0523、0525、1465、1744
04 июн 2021, 11:22
04 июн 2021, 11:22
cc78fdd
Код
Авторство
О чём код?
package leetcode func findMaxLength(nums []int) int { dict := map[int]int{} dict[0] = -1 count, res := 0, 0 for i := 0; i < len(nums); i++ { if nums[i] == 0 { count-- } else { count++ } if idx, ok := dict[count]; ok { res = max(res, i-idx) } else { dict[count] = i } } return res } func max(a, b int) int { if a > b { return a } return b }