【力扣】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;
    }
};
相关推荐
练习时长一年10 分钟前
LeetCode热题100(杨辉三角)
算法·leetcode·职场和发展
lzllzz2327 分钟前
bellman_ford算法
算法
栈与堆37 分钟前
LeetCode 19 - 删除链表的倒数第N个节点
java·开发语言·数据结构·python·算法·leetcode·链表
sunfove39 分钟前
麦克斯韦方程组 (Maxwell‘s Equations) 的完整推导
线性代数·算法·矩阵
Rui_Freely1 小时前
Vins-Fusion之 SFM准备篇(十二)
人工智能·算法·计算机视觉
yyy(十一月限定版)1 小时前
matlab矩阵的操作
算法·matlab·矩阵
努力学算法的蒟蒻1 小时前
day58(1.9)——leetcode面试经典150
算法·leetcode·面试
txinyu的博客2 小时前
map和unordered_map的性能对比
开发语言·数据结构·c++·算法·哈希算法·散列表
搞笑症患者2 小时前
压缩感知(Compressed Sensing, CS)
算法·最小二乘法·压缩感知·正交匹配追踪omp·迭代阈值it算法
im_AMBER2 小时前
Leetcode 101 对链表进行插入排序
数据结构·笔记·学习·算法·leetcode·排序算法