https://oj.leetcode.com/problems/string-to-integer-atoi/
Http://fisherlei.blogspot.com/2013/01/leetcode-string-to-integer-atoi.html
Public class solution { public int atoi (STRING&NBSP;STR) { // validations if (str == null | | str.length () == 0) return 0; char[] chars = str.trim (). ToCharArray (); int len = chars.length; int i = 0; // Check +/- boolean negative = false; if (chars[0] == ' + ') { i++; } else if (Chars[0] == '-') { negative = true; i ++; } double result = 0; for (; i < len ; i ++) { char c = chars[i]; if (c >= ' 0 ' && c <= ' 9 ') result = result * 10 + (c - ' 0 '); else break; // Break the loop when meeting invalid chars. } if (negative) result = -result; if ( Result > integer.max_value) return integer.max_value; if (Result < integer.min_value) return Integer.MIN_VALUE; return ( int) result; }}
[Leetcode]8 String to Integer (atoi)