1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/执行操作后的变量值 [final-value-of-variable-after-performing-operations].html
2022-03-29 12:43:11 +08:00

59 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>存在一种仅支持 4 种操作和 1 个变量 <code>X</code> 的编程语言:</p>
<ul>
<li><code>++X</code><code>X++</code> 使变量 <code>X</code> 的值 <strong></strong> <code>1</code></li>
<li><code>--X</code><code>X--</code> 使变量 <code>X</code> 的值 <strong></strong> <code>1</code></li>
</ul>
<p>最初,<code>X</code> 的值是 <code>0</code></p>
<p>给你一个字符串数组 <code>operations</code> ,这是由操作组成的一个列表,返回执行所有操作后,<em> </em><code>X</code><strong>最终值</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>operations = ["--X","X++","X++"]
<strong>输出:</strong>1
<strong>解释:</strong>操作按下述步骤执行:
最初X = 0
--XX 减 1 X = 0 - 1 = -1
X++X 加 1 X = -1 + 1 = 0
X++X 加 1 X = 0 + 1 = 1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>operations = ["++X","++X","X++"]
<strong>输出:</strong>3
<strong>解释:</strong>操作按下述步骤执行:
最初X = 0
++XX 加 1 X = 0 + 1 = 1
++XX 加 1 X = 1 + 1 = 2
X++X 加 1 X = 2 + 1 = 3
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>operations = ["X++","++X","--X","X--"]
<strong>输出:</strong>0
<strong>解释:</strong>操作按下述步骤执行:
最初X = 0
X++X 加 1 X = 0 + 1 = 1
++XX 加 1 X = 1 + 1 = 2
--XX 减 1 X = 2 - 1 = 1
X--X 减 1 X = 1 - 1 = 0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= operations.length &lt;= 100</code></li>
<li><code>operations[i]</code> 将会是 <code>"++X"</code><code>"X++"</code><code>"--X"</code><code>"X--"</code></li>
</ul>