【力扣】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;
    }
};
相关推荐
gsfl4 小时前
双指针算法
算法·双指针
郝学胜-神的一滴4 小时前
矩阵的奇异值分解(SVD)及其在计算机图形学中的应用
程序人生·线性代数·算法·矩阵·图形渲染
电子_咸鱼9 小时前
LeetCode——Hot 100【电话号码的字母组合】
数据结构·算法·leetcode·链表·职场和发展·贪心算法·深度优先
仰泳的熊猫9 小时前
LeetCode:785. 判断二分图
数据结构·c++·算法·leetcode
rit84324999 小时前
基于MATLAB实现基于距离的离群点检测算法
人工智能·算法·matlab
my rainy days11 小时前
C++:友元
开发语言·c++·算法
haoly198911 小时前
数据结构和算法篇-归并排序的两个视角-迭代和递归
数据结构·算法·归并排序
微笑尅乐11 小时前
中点为根——力扣108.讲有序数组转换为二叉搜索树
算法·leetcode·职场和发展
im_AMBER12 小时前
算法笔记 05
笔记·算法·哈希算法