Ad
  • Custom User Avatar

    and the check for length can be done before the loop

  • Default User Avatar

    exactly, strange it got so many 'clever' votes.

  • Custom User Avatar

    A null input should either throw a NullPointerException (discouraged) or should gracefully delegate the null-handling back to the caller by returning null (prefered).
    Converting null to an empty string (or any other "empty" object, for that matter) is a bad practice that leads to confusion in more complex code as to where exactly the unexpected "empty" dummy object originated from. An empty string is no different from any other empty object – it has no semantic value but is merely a meaningless stopgap. DON'T PRODUCE EMPTY OBJECTS!

  • Custom User Avatar

    I have not considered this yet. I believe if 2 (or more) solutions both have the shortest length, either one should be accepted, as the criteria states

    "The shortest solution is the one containing the least nodes labeled 'P'."

    So, they would both work. I will add this later, thanks.

  • Custom User Avatar

    Thanks but don't deserve an issue that are for rather big problems:-)

  • Custom User Avatar

    Already written :
    2) The encode method should return an empty String if a null parameter is passed.