Why " -0012a42" is a valid input?


  • 1
    M

    Integer.parseInt(" -0012a42") throws an NumberFormatException.


  • 4
    S

    Have you read the requirements?

    The function first discards as many whitespace characters as necessary
    until the first non-whitespace character is found. Then, starting from
    this character, takes an optional initial plus or minus sign followed
    by as many numerical digits as possible, and interprets them as a
    numerical value.

    For -0012a42, you need to convert -0012 to int.


  • 0
    M

    Thank you! I didn't the requirements at first, just thought over the exceptions by myself and used Integer.parseInt to test my idea.


Log in to reply
 

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