title: ArrayList Removing first element
body: <p>This is the given question:
  Given a non-negative number represented as an array of digits,</p>
  
  <p>add 1 to the number ( increment the number represented by the digits ).</p>
  
  <p>The digits are stored such that the most significant digit is at the head of the list.</p>
  
  <p>Example:</p>
  
  <p>If the vector has [1, 2, 3]</p>
  
  <p>the returned vector should be [1, 2, 4]</p>
  
  <p>as 123 + 1 = 124.</p>
  
  <p>This is my code:</p>
  
  <pre><code> public class Solution {
      public ArrayList&lt;Integer&gt; plusOne(ArrayList&lt;Integer&gt; A) {       
          int carry = 1;
          int length = A.size();
          ArrayList result = new ArrayList();
  
          for( int i = length - 1; i &gt;=0; i-- ){
              int val = A.get(i) + carry;
              result.add(0,val % 10);
              carry = val / 10;
          }
  
          if (carry == 1){
              result.add(0,1);
          }
  
          for (int j = 0; j &lt; result.size(); j++){
              if(result.get(j).equals(0))
                  result.remove(j);
              else
                  break;
         }
  
          return result;
  
      }
    }
  </code></pre>
  
  <p>However, in the test case: 
  A : [ 0, 6, 0, 6, 4, 8, 8, 1 ]</p>
  
  <p>it says my function returns</p>
  
  <p>6 6 4 8 8 2 </p>
  
  <p>while the correct answer is </p>
  
  <p>6 0 6 4 8 8 2</p>
  
  <p>I have no idea what is wrong with my code.</p>
  
  <p>Thanks!</p>