【力扣】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;
    }
};
相关推荐
xlq2232220 小时前
29.哈希(下)
算法·哈希算法·散列表
阿昭L20 小时前
leetcode链表是否有环
算法·leetcode·链表
yaoh.wang20 小时前
力扣(LeetCode) 83: 删除排序链表中的重复元素 - 解法思路
程序人生·算法·leetcode·链表·面试·职场和发展
阿昭L20 小时前
leetcode旋转链表
算法·leetcode·链表
山楂树の20 小时前
有效的括号(栈)
数据结构·算法
im_AMBER20 小时前
Leetcode 81 【滑动窗口(定长)】
数据结构·笔记·学习·算法·leetcode
xu_yule20 小时前
算法基础(背包问题)-完全背包
c++·算法·动态规划·完全背包
x9766620 小时前
使用 HMAC-SHA256算法对MCU UID进行加密
单片机·嵌入式硬件·算法
gfdhy20 小时前
【c++】素数详解:概念、定义及高效实现(判断方法 + 筛法)
开发语言·c++·算法·数学建模·ai编程
Swift社区20 小时前
LeetCode 452 - 用最少数量的箭引爆气球
算法·leetcode·职场和发展