【力扣】2011. 执行操作后的变量值

2011. 执行操作后的变量值

总结,玩爽了,回归。

java 复制代码
class Solution {
    public int finalValueAfterOperations(String[] operations) {
        int x = 0;
        for(String op : operations) {
            if (op.equals("X++") || op.equals("++X")){
                x ++ ;
            }
            else x -- ;
        }
        return x;
    }
}
cpp 复制代码
class Solution {
public:
    int finalValueAfterOperations(vector<string>& operations) {
        int x = 0;
        for (auto &op : operations) {
            op[1] == '+' ? x ++ : x -- ;
        }
        return x;
    }
};
相关推荐
星释18 小时前
Rust 练习册 :Pythagorean Triplet与数学算法
开发语言·算法·rust
星释18 小时前
Rust 练习册 :Nth Prime与素数算法
开发语言·算法·rust
多喝开水少熬夜18 小时前
Trie树相关算法题java实现
java·开发语言·算法
WBluuue19 小时前
数据结构与算法:树上倍增与LCA
数据结构·c++·算法
bruk_spp19 小时前
牛客网华为在线编程题
算法
黑屋里的马21 小时前
java的设计模式之桥接模式(Bridge)
java·算法·桥接模式
sin_hielo21 小时前
leetcode 1611
算法·leetcode
李小白杂货铺21 小时前
识别和破除信息茧房
算法·信息茧房·识别信息茧房·破除信息茧房·算法推荐型茧房·观点过滤型茧房·茧房
来荔枝一大筐1 天前
C++ LeetCode 力扣刷题 541. 反转字符串 II
c++·算法·leetcode