A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.
count instances where the second "6" is actually a 7.
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==nums[i+1])
count++;
}
return count;
}
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==6 && nums[i+1] == 7)
count++;
}
return count;
}
which would detect one of those pairs - the 6,7 combination.public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==nums[i+1]|| nums[i]==6&&nums[i+1]==7)
count++;
}
return count;
}
i wrote as above . It pass all the tests.if (nums[i]==nums[i+1] ... )
, you don't really want this
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==6&&nums[i+1]==7)
count++;
}
return count;
}
Expected Run
array667({6, 6, 2}) → 1 0 X
array667({6, 6, 2, 6}) → 1 0 X
array667({6, 7, 2, 6}) → 1 1 OK
array667({6, 6, 2, 6, 7}) → 2 1 X
array667({1, 6, 3}) → 0 0 OK
array667({6, 1}) → 0 0 OK
array667({}) → 0 0 OK
array667({3, 6, 7, 6}) → 1 1 OK
array667({3, 6, 6, 7}) → 2 1 X
array667({6, 3, 6, 6}) → 1 0 X
array667({6, 7, 6, 6}) → 2 1 X
array667({1, 2, 3, 5, 6}) → 0 0 OK
array667({1, 2, 3, 6, 6}) → 1 0 X
return the number of times that two 6's are next to each other
if(nums[i]==6&&nums[i+1]==7)
if(nums[i]==6 && (nums[i+1] == 6 || nums[i+1] == 7))
public int array667(int[] nums) {
int count=0;
for(int i=0;i<nums.length-1;i++)
{
if(nums[i]==6 && (nums[i+1] == 6 || nums[i+1] == 7))
count++;
}
return count;
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.