String to Integer (atoi)

https://leetcode.com/problems/string-to-integer-atoi/description/
github: String to Integer(atoi)

Checking point:

  • null or empty string
  • white spaces
  •  +/- sign
  • calculate real value
  • handle min & max

github: String to Integer(atoi)

** trim white space before checking string is empty, so we can ignore whitespaces before number **

    //trim white space
      str = str.trim();

      if(str.isEmpty()){
          return 0;
      }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s