实现一个基本的计算器来计算一个简单的字符串表达式的值。 字符串表达式仅包含非负整数,+, - ,*, 四种运算符和空格 。 整数除法仅保留整数部分。 示例 : 输入: "3+2*2" 输出: 7 输入:"3+52" 输出: 5
示例1
输入
" 3/2 "
输出
1
备注:
语言不限
加载中...
import java.util.*; public class Solution { /** * 计算器 * @param s string字符串 公式 * @return long长整型 */ public long calculate (String s) { // write code here } }
class Solution { public: /** * 计算器 * @param s string字符串 公式 * @return long长整型 */ long long calculate(string s) { // write code here } };
# # 计算器 # @param s string字符串 公式 # @return long长整型 # class Solution: def calculate(self , s ): # write code here
/** * 计算器 * @param s string字符串 公式 * @return long长整型 */ function calculate( s ) { // write code here } module.exports = { calculate : calculate };
# # 计算器 # @param s string字符串 公式 # @return long长整型 # class Solution: def calculate(self , s ): # write code here
" 3/2 "
1