[Wrong Answer] Output is the same as expected but i got WA


  • 0
    O

    Input: " a b "
    Output: "b a"
    Expected: "b a"

    I cannot find why this is wrong


  • 0
    S

    It is better to paste code and explain its idea to check it out. Maybe code returned some un-printable character due to some underlying overflow error.


  • 0
    M

    When you get the wrong answer, but the output value appears identical to the expected value, there are two main problems that may have occurred in the code. The first, as Shangrila mentioned in the comment, is that when you were forming the string, you included some unprintable characters in the string, so that it appears to be the same, but when put through:

    for(int i=0;c[i];i++) print( (int)c[i] );
    

    prints more than the expected characters.

    The other possibility is that you are actually printing the result before returning it. Leetcode's judge compares against the first output, so a printed output will be taken instead of the returned output, and will likely be considered different. I'm not certain this result occurs in the case of returned strings, but I believe it does.


  • 0
    O

    thx, it really contains an unexpected character at the end of my output


Log in to reply
 

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