mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
31 lines
876 B
HTML
31 lines
876 B
HTML
<p>Given an arithmetic equation consisting of positive integers, +, -, * and / (no paren­theses), compute the result.</p>
|
|
|
|
|
|
|
|
<p>The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero.</p>
|
|
|
|
|
|
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input: </strong>"3+2*2"
|
|
|
|
<strong>Output:</strong> 7
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> " 3/2 "
|
|
|
|
<strong>Output:</strong> 1</pre>
|
|
|
|
|
|
|
|
<p><strong>Example 3:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> " 3+5 / 2 "
|
|
|
|
<strong>Output:</strong> 5
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong>Note:</strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>You may assume that the given expression is always valid.</li>
|
|
|
|
<li>Do not use the eval built-in library function.</li>
|
|
|
|
</ul>
|
|
|