Leetcode LCP 50. 宝石补给

Leetcode LCP 50. 宝石补给

Leetcode LCP 50. 宝石补给_第1张图片
Leetcode LCP 50. 宝石补给_第2张图片

class Solution {
public:
    int giveGem(vector<int>& gem, vector<vector<int>>& operations) {
        for(auto& x:operations)
        {
            int give=x[0],get=x[1];
            int val=gem[give]/2;
            gem[give]-=val;
            gem[get]+=val;
        }
        return *max_element(gem.begin(),gem.end())-*min_element(gem.begin(),gem.end());
        
    }
};

你可能感兴趣的:(Leetcode,leetcode,C++)