Zheaoli / do-something-right

MIT License
37 stars 3 forks source link

2022-12-23 #460

Open Zheaoli opened 1 year ago

Zheaoli commented 1 year ago

2022-12-23

dreamhunter2333 commented 1 year ago
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
/*
 * @lc app=leetcode.cn id=2011 lang=cpp
 *
 * [2011] 执行操作后的变量值
 */

// @lc code=start
class Solution
{
public:
    unordered_map<string, int> map = {{"X++", 1}, {"++X", 1}, {"--X", -1}, {"X--", -1}};

    int finalValueAfterOperations(vector<string> &operations)
    {
        int res = 0;
        for (auto &&op : operations)
        {
            res += map[op];
        }
        return res;
    }
};
// @lc code=end

微信id: 而我撑伞 来自 vscode 插件