Testcase correct but submission shows wrong answer


  • 0
    S

    0_1506226624320_Screen Shot 2017-09-23 at 11.11.13 PM.png


  • 0

    Can we see you code? Did you use global variables? Global variables may cause issue when running all test cases.


  • 0
    A

    Similar thing happened with me.
    Lost a lot of time over this.
    Even the sample example result is wrong. Should be 30 in place of 15 in Example 1.

    My test case passes with the input but fails when I actually submit.
    The input where it fails:
    ["15483","-20523","C","C","9061","26083","+","C","4702","+","D","10260","-525","C","+","15023","-20005","-1647","C","-12853","20706","D","-21983","24892","10570","D","1215","D","D","+","3854","20505","C","D","-18850","-2170","27914","-26175","+","3188","+","+","21804","D","+","-847","D","26184","14945","C","D","+","+","13795","+","1839","15755","2627","-2090","C","C","29743","24319","D","-22624","20374","+","D","2631","+","7296","-5109","9454","-10466","D","C","+","17555","+","12144","D","16710","27969","22863","D","8521","+","D","C","-25486","-1137","9782","25633","-12031","-11248","+","C","-13559","D","D"]

    The actual input received by the code:
    ["8373","C","9034","-17523","D","1492","7558","-5022","C","C","+","+","-16000","C","+","-18694","C","C","C","-19377","D","-25250","20356","C","-1769","-8303","C","-25332","29884","C","+","C","-29875","-15374","C","+","14584","13773","+","17037","-28248","+","16822","D","+","+","-19357","-26593","-8548","4776","D","-8244","378","+","-19269","-25447","18922","-16782","2886","C","-17788","D","-22256","C","308","-9185","-19074","1528","28424","D","8658","C","7221","-13704","8995","-21650","22567","-29560","D","-9807","25632","6817","28654","D","-18574","C","D","20103","7875","C","9911","23951","C","D","C","+","18219","-20922","D","-24923"]
    Retrieved the actual input by using stdout in code.

    Please help!


  • 0

    Could you tell us what was your second last sum?


  • 0
    9

    Same issue here.
    0_1506235401069_Screen Shot 2017-09-23 at 11.41.09 PM.png
    The test case is ["63","D","-53","95","85","-89","+","61","6","-12"]
    I System.out.print the array value, and I get the number unmatched to the test case and submit one. I use int[] to record the number per round first. This is my code
    @BryanBo-Cao can you solve this topic too?

    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.