Wrong answer with "AB"

  • 1

    Strange, I got wrong answer, but the expected and output are exactly the same.!!!

    Input: "AB", 2
    Output: "AB"
    Expected: "AB"

    Someone could explain it for me?

  • 2

    Without looking at your code, I can think of 2 possibilities. The first is that you have unprintable characters inside the string, so that they print the same values, but aren't actually the same. Try running your answer through the following function or its equivalent in your language of choice:

    for(char c : s)

    If you get more ints than you expect, you have unprintable ones in your string.

    The second possibility is that you are printing the output in your code instead of, or in addition to, returning it. As leetcode uses the first output to test against, the printed value would be compared against a string, which has additional data in it that causes it to be unequal. Remove any prints in your code, unless the problem specifically asks for them (as far as I remember, none of them do).

  • 0

    i do find I have some unprintable character, thx

Log in to reply

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