Golang | Leetcode Golang题解之第474题一和零

题目:

题解:

Go 复制代码
func findMaxForm(strs []string, m, n int) int {
    dp := make([][]int, m+1)
    for i := range dp {
        dp[i] = make([]int, n+1)
    }
    for _, s := range strs {
        zeros := strings.Count(s, "0")
        ones := len(s) - zeros
        for j := m; j >= zeros; j-- {
            for k := n; k >= ones; k-- {
                dp[j][k] = max(dp[j][k], dp[j-zeros][k-ones]+1)
            }
        }
    }
    return dp[m][n]
}

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}
相关推荐
poemyang3 小时前
Goroutine间的“灵魂管道”:Channel如何实现数据同步与因果传递?
golang·并发编程
Lazy龙4 小时前
Golang协程
golang
235164 小时前
【LeetCode】146. LRU 缓存
java·后端·算法·leetcode·链表·缓存·职场和发展
tkevinjd7 小时前
反转链表及其应用(力扣2130)
数据结构·leetcode·链表
程序员烧烤9 小时前
【leetcode刷题007】leetcode116、117
算法·leetcode
Swift社区12 小时前
LeetCode 395 - 至少有 K 个重复字符的最长子串
算法·leetcode·职场和发展
Espresso Macchiato12 小时前
Leetcode 3710. Maximum Partition Factor
leetcode·职场和发展·广度优先遍历·二分法·leetcode hard·leetcode 3710·leetcode双周赛167
巴里巴气12 小时前
第15题 三数之和
数据结构·算法·leetcode
一根甜苦瓜13 小时前
Go语言Slice的一道骚题
开发语言·后端·golang
驰羽13 小时前
[GO]Go语言泛型详解
开发语言·golang·xcode