Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.
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.