hhh...


  • 0
    L
    public int evalRPN(String[] tokens) {
    		int[] arr = new int[tokens.length];
    		int temp = 0,front =0,back =0;
    		for(int i = 0 ; i < tokens.length ; i++) {
    			if("*".equals(tokens[i])) {
    				back = arr[--temp];
    				front = arr[--temp];
    				arr[temp++] = front * back;
    			}else if("-".equals(tokens[i])) {
    				back = arr[--temp];
    				front = arr[--temp];
    				arr[temp++] = front - back;
    			}else if("+".equals(tokens[i])){
    				back = arr[--temp];
    				front = arr[--temp];
    				arr[temp++] = front + back;
    			}else if("/".equals(tokens[i])){
    				back = arr[--temp];
    				front = arr[--temp];
    				arr[temp++] = front / back;
    			}else{
    				arr[temp++] = Integer.parseInt(tokens[i]);
    			}
    				
    		}
    		return arr[0];
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.