leetcodeLCCUP:1. 宝石补给【简单模拟】

阅读 20

2022-04-17

在这里插入图片描述

分析

每个人有初始的宝石
然后x给y它宝石的一半
求最后最多宝石和最小宝石的差

ac code

class Solution:
    def giveGem(self, gem: List[int], operations: List[List[int]]) -> int:
        for op in operations:
            x, y = op
            give = gem[x] // 2
            gem[x] -= give
            gem[y] += give
        return max(gem) - min(gem)

总结

我爱模拟
简单的那种

精彩评论(0)

0 0 举报