1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/基本计算器 II [basic-calculator-ii].html
2022-03-29 12:43:11 +08:00

43 lines
1.3 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>给你一个字符串表达式 <code>s</code> ,请你实现一个基本计算器来计算并返回它的值。</p>
<p>整数除法仅保留整数部分。</p>
<p>你可以假设给定的表达式总是有效的。所有中间结果将在&nbsp;<code>[-2<sup>31</sup>, 2<sup>31</sup>&nbsp;- 1]</code> 的范围内。</p>
<p><strong>注意:</strong>不允许使用任何将字符串作为数学表达式计算的内置函数,比如 <code>eval()</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "3+2*2"
<strong>输出:</strong>7
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = " 3/2 "
<strong>输出:</strong>1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = " 3+5 / 2 "
<strong>输出:</strong>5
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 3 * 10<sup>5</sup></code></li>
<li><code>s</code> 由整数和算符 <code>('+', '-', '*', '/')</code> 组成,中间由一些空格隔开</li>
<li><code>s</code> 表示一个 <strong>有效表达式</strong></li>
<li>表达式中的所有整数都是非负整数,且在范围 <code>[0, 2<sup>31</sup> - 1]</code></li>
<li>题目数据保证答案是一个 <strong>32-bit 整数</strong></li>
</ul>