title: reference binding to null pointer of type 'value_type'
body: <p>This is leetcode 26. Given a sorted array, remove the duplicates in-place such that each element appear only once and return the new length. An example is given <code>nums = [1,1,2]</code>, the function should return <code>[1,2]</code>.</p>
  
  <p>Below is my code. I delete all the other duplicates, just leave one of them. However I always got an error of <code>reference binding to null pointer of type 'value_type'</code> when submitting. I would appreciate if anyone can help me with this!</p>
  
  <pre><code>class Solution {
  public:
      int removeDuplicates(vector&lt;int&gt;&amp; nums) {
          int i = 0;
          while(i &lt; nums.size() - 1) {
              if (nums[i] == nums[i + 1]) {
                  nums.erase(nums.begin() + i);
              } 
              else i++;
          }
          return nums.size();
      }
  };
  </code></pre>