/* 8. String to Integer (atoi)
 */

public class Solution {
  private static final int max_div_10 = Integer.MAX_VALUE / 10;
  public int myAtoi(String str) {
    int i = 0, n = str.length();
    while (i < n && Character.isWhitespace(str.charAt(i))) {
      i++;
    }
    int sign = 1;
    if (i < n && str.charAt(i) == '+') {
      i++;
    } 
    else if (i < n && str.charAt(i) == '-') {
      sign = -1;
      i++;
    }
    int number = 0;
    while (i < n && Character.isDigit(str.charAt(i))) {
      int digit = Character.getNumericValue(str.charAt(i));
      if (number > max_div_10 || (number == max_div_10 && digit >= 8)) {
        return (sign == 1) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
      }
      number = number * 10 + digit;
      i++;
    }
    return sign * number;
  }
}

@@ -32,16 +32,18 @@
 %0A */%0D%0A%0D%0A
+%0D%0A
 public c
@@ -352,17 +352,16 @@
 ;%0D%0A    %7D
- 
 %0D%0A    el

update 8.