Here is the question: Given an array of ints, return the number of times that two 6's are next to each other in the array. Also count instances where the second "6" is actually a 7.
Here is the code:
public int array667(int[] nums) {
int len = nums.length;
int count = 0;
for (int i=0;i<len-1;i++){
if ((nums[i]==6) && (nums[i+1]==6||nums[i+1]==7)){
count++;
}
}
return count;
}
I don't understand why it has to be initialized at i-1 in order to work. Please explain
Also are there any other scenarios in which i-1 would be needed maybe even not for just initializing i.