2011. 执行操作后的变量值

[2011. 执行操作后的变量值] (https://leetcode.cn/problems/final-value-of-variable-after-performing-operations/description/)

class Solution {
    public int finalValueAfterOperations(String[] operations) {
        int res = 0;
        for (String operation : operations) {
            switch (operation) {
                case "--X" :
                case "X--" :
                    res --; break;
                case "X++" :
                case "++X" :
                    res ++; break;
                default: break;
            }
        }
        return res;
    }
}
posted @ 2022-12-23 17:45  Eiffelzero  阅读(17)  评论(0)    收藏  举报