Here is my code:

```
public class Solution {
public int maxSubArray(int[] nums) {
int max = nums[0],maxEndingHere = nums[0];
for(int i=1;i<nums.length;i++){
maxEndingHere = Math.max(maxEndingHere+nums[i],nums[i]);
max = Math.max(maxEndingHere,max);
}
return max;
}
}
```

I receive a "Time Limit Exceed" error when I run it, but if I simply change the for loop to be:

```
for(int i=1;i<nums.length;++i)
```

The test cases pass properly. Can someone tell me why??

Thank you very much!