Conflict result. Same test case. Pass Run Code, but fail on Submit?


  • 0
    9

    I copy my fail submit case to run code, but it works. When I print out the case input, it consist with Run Code, but not with Submit. The attachment is my screen and my code.0_1506273147613_Screen Shot 2017-09-23 at 11.41.09 PM.png
    public int calPoints(String[] ops) {

        int sum = 0;
        int[] scores = new int[ops.length];
        
        for (int i = 0; i < ops.length; i++){
            if (ops[i].equals("C") ) { //numbers
                
                scores[i] = Integer.MIN_VALUE;
                scores[i-1] = Integer.MIN_VALUE;
                
            }else if(ops[i].equals("D")){
                // System.out.println("D");
                // System.out.println(i);
                
                int j = i;
                
                while( j - 1 > -1){
                    if (scores[j - 1] != Integer.MIN_VALUE){
                        // System.out.println("j-1");
                        // System.out.println(j);
    
                        scores[i] = scores[j - 1] * 2;
                        break;
                    }
                    
                    j--;
                }
                
            }else if (ops[i].equals("+")){
                int j = i;
                while( j-2 > -1){
                    if ( scores[j - 1] != Integer.MIN_VALUE){
                        scores[i] = scores[j-1];
                    }
                    if ( scores[j - 2] != Integer.MIN_VALUE){
                        scores[i] += scores[j-2];
                        break;
                    }
                    j--;
                }
            }else{                
                // Integer.parseInt(op)
                System.out.println(ops[i]);
                scores[i] = Integer.parseInt(ops[i]);
            }   
        }
        
        // System.out.println(" ");
        
        for (int i:scores){
            // System.out.println(i);
            if (i != Integer.MIN_VALUE){
                sum += i;
            }
        }
        
        return sum;
        
    }

Log in to reply
 

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