Golang | Leetcode Golang题解之第486题预测赢家

题目:

题解:

Go 复制代码
func PredictTheWinner(nums []int) bool {
    return total(nums, 0, len(nums) - 1, 1) >= 0
}

func total(nums []int, start, end int, turn int) int {
    if start == end {
        return nums[start] * turn
    }
    scoreStart := nums[start] * turn + total(nums, start + 1, end, -turn)
    scoreEnd := nums[end] * turn + total(nums, start, end - 1, -turn)
    return max(scoreStart * turn, scoreEnd * turn) * turn
}

func max(x, y int) int {
    if x > y {
        return x
    }
    return y
}
相关推荐
渐暖°5 分钟前
【leetcode算法从入门到精通】5. 最长回文子串
vscode·算法·leetcode
今天_也很困6 分钟前
LeetCode热题100-560. 和为 K 的子数组
java·算法·leetcode
v_for_van19 分钟前
力扣刷题记录2(无算法背景,纯C语言)
c语言·算法·leetcode
alphaTao26 分钟前
LeetCode 每日一题 2026/1/26-2026/2/1
算法·leetcode
We་ct1 小时前
LeetCode 54. 螺旋矩阵:两种解法吃透顺时针遍历逻辑
前端·算法·leetcode·矩阵·typescript
We་ct2 小时前
LeetCode 36. 有效的数独:Set实现哈希表最优解
前端·算法·leetcode·typescript·散列表
tod1133 小时前
力扣高频 SQL 50 题阶段总结(四)
开发语言·数据库·sql·算法·leetcode
iAkuya4 小时前
(leetcode)力扣100 57电话号码的字母组合(回溯)
算法·leetcode·深度优先
zhangfeng11335 小时前
Ollama 支持模型微调但是不支持词库,支持RAG,go语言开发的大模型的推理应用,
人工智能·深度学习·golang
Dr.Kun7 小时前
【鲲码园PsychoPy】Go/No-go范式
开发语言·后端·golang