Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
Become a Premium Member and unlock a new, free course in leading technologies each month.
public boolean has22(int[] nums) {
boolean result=false;
int sum=0;
for(int n:nums){
if(n==2)
result=true;
}
return result;
}
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
public boolean has22(int[] nums) {
for(int y=0;y<nums.length-1;y++){xxxxxxxxxxx){return true;}}
return false;
}
public boolean has22(int[] nums) {
boolean result=false;
int sum=0;
int len=nums.length;
for(int i=0;i<len-1;i++){
if(nums[i]==2&&nums[i+1]==2)
result=true;
}
return result;
}
You could return true as soon as you find two 2's next to each other and save a little processing time.
public boolean has22(int[] nums) {
// boolean result=false;
int sum=0;
int len=nums.length;
for(int i=0;i<len-1;i++){
if(nums[i]==2&&nums[i+1]==2)
return true;
}
// return result;
return false;
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.