设为首页 加入收藏

TOP

leetcode 227: Basic Calculator II
2015-11-21 00:58:49 来源: 作者: 【 】 浏览:2
Tags:leetcode 227: Basic Calculator

Basic Calculator II

Total Accepted: 1485 Total Submissions: 8042

Implement a basic calculator to eva luate a simple expression string.

The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero.

You may assume that the given expression is always valid.

Some examples:

"3+2*2" = 7
" 3/2 " = 1
" 3+5 / 2 " = 5

Note: Do not use the eva l built-in library function.

[思路]

pass两遍, 第一遍, 先解决乘除, 第二遍, 做加减.

[CODE]

?

public class Solution {
    public int calculate(String s) {
        if(s==null || s.length()==0) return 0;
        
        LinkedList
  
    list = new LinkedList
   
    (); for(int i=0; i
    
     

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇[LeetCode] Regular Expression M.. 下一篇UVALive - 2326 Moving Tables 贪..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: