当前位置:网站首页>2011. 执行操作后的变量值
2011. 执行操作后的变量值
2022-06-22 00:28:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:2011. 执行操作后的变量值
描述:存在一种仅支持 4 种操作和 1 个变量 X 的编程语言:
++X 和 X++ 使变量 X 的值 加 1
–X 和 X-- 使变量 X 的值 减 1
最初,X 的值是 0
给你一个字符串数组 operations ,这是由操作组成的一个列表,返回执行所有操作后, X 的 最终值 。
解题思路
1、按题目要求顺序编程;
原代码##
class Solution {
public:
int finalValueAfterOperations(vector<string>& operations) {
int x = 0;
int len = operations.size();
for (int i = 0; i < len; ++i) {
for (int j = 0; j < 3; ++j) {
if (operations[i][j] == '-') {
x--;
break;
}
if (operations[i][j] == '+') {
x++;
break;
}
}
}
return x;
}
};
边栏推荐
猜你喜欢

Counter完之后,想统计字符串长度大于2的结果

动态规划-01背包,分割等和子集,最后一块石头的重量

The appearance, space, safety and power are all upgraded. The xinjietu x70s will be put on the market from 87900 yuan

ShardingSphere-proxy-5.0.0分布式哈希取模分片实现(四)

yolov3 3D 语义点云paper阅读

RNN的简单整理
![[Environmental stepping pit] pycharm reports an error when using QT](/img/ac/665d4052919a1783ba6ac8edcb06ba.png)
[Environmental stepping pit] pycharm reports an error when using QT

How to remove duplication in left join from a simple example

IDEA 提示 Duplicated code fragment (15 lines long)

Pytorch learning 10: statistical operations
随机推荐
Spark RDD案例:词频统计
Pytorch learning 13: implement letnet and learning nn Module related basic operations
【环境踩坑】pycharm使用qt时报错
对“基于tensorflow+RNN的新浪新闻文本分类”一文的图示化理解
Virtual variables and formatting characters in debugging
LVGL的一些介绍和移植
4275. Dijkstra序列
eVC4编的程序不能在emulator上运行
【Redis】事件驱动框架源码分析(单线程)
【ÑÖÏ模拟赛】花萎(矩阵加速,循环卷积,高斯消元)
English grammar_ Adverb_ fairly / rather
FLowable运行时事务相关的表和表结构
clean,compile,build,install,package区别
【DailyFresh】课程记录3--商品搜索相关
Find find files with different extensions
52 classes 110 common components and frameworks
What does container cloud mean? What is the difference with fortress machine?
ShardingSphere-proxy-5.0.0分布式哈希取模分片实现(四)
Shardingsphere-proxy-5.0.0 implementation of distributed hash modulo fragmentation (4)
[glib][gstreamer] plug in writing ideas -- inheritance, override and virtual functions