[20221223]每日一题

简单的模拟

class Solution {
public:
    int finalValueAfterOperations(vector<string>& operations) {
        int ans = 0;
        for (auto str : operations) {
            if (str[0] == 'X') {
                if (str[1] == '+') ans += 1;
                else ans -= 1;
            } else if (str[0] == '+') {
                ans += 1;
            } else {
                ans -= 1;
            }
        }
        return ans;
    }

};

posted @ 2022-12-23 09:35  zhanghanLeo  阅读(25)  评论(0)    收藏  举报