tag:blogger.com,1999:blog-5872623838295077986.post3545932718176745100..comments2024-03-20T01:07:56.465-07:00Comments on JavaProblems.com - Free coding problems and exercises: Java > AP-1 > scoresClump (CodingBat Solution)Unknownnoreply@blogger.comBlogger5125tag:blogger.com,1999:blog-5872623838295077986.post-16986230380726183732022-04-06T00:44:05.709-07:002022-04-06T00:44:05.709-07:00public boolean scoresClump(int[] scores) {
for(i...public boolean scoresClump(int[] scores) {<br /> for(int i=0;i<scores.length-2;i++){<br /> if((scores[i+2])-(scores[i])==2){<br /> return true; <br /> }<br /> }<br /> return false;<br />}Anonymoushttps://www.blogger.com/profile/02065146092316164872noreply@blogger.comtag:blogger.com,1999:blog-5872623838295077986.post-13638786898650943542021-10-29T06:45:08.735-07:002021-10-29T06:45:08.735-07:00public boolean scoresClump(int[] scores)
{
for(...public boolean scoresClump(int[] scores) <br />{<br /> for(int i = 2; i < scores.length; i++)<br /> {<br /> if(Math.abs(scores[i-2]-scores[i]) <= 2) return true;<br /> }<br /> <br /> return false;<br />}<br />Sinuserhttps://www.blogger.com/profile/08399295430731617209noreply@blogger.comtag:blogger.com,1999:blog-5872623838295077986.post-5783481858525012992017-08-24T23:04:16.694-07:002017-08-24T23:04:16.694-07:00for(int i=scores.length-1; i>=2; i--){
if(s...for(int i=scores.length-1; i>=2; i--){<br /> if(scores[i] - scores[i-2] <=2) return true;<br /> }<br /> <br /> return false;Anonymoushttps://www.blogger.com/profile/13811516235171204919noreply@blogger.comtag:blogger.com,1999:blog-5872623838295077986.post-76914714261671915392017-06-05T09:47:36.423-07:002017-06-05T09:47:36.423-07:00public boolean scoresClump(int[] scores) {
for(i...public boolean scoresClump(int[] scores) {<br /> for(int i = 0; i < scores.length - 2; i++) {<br /> if(scores[i+2] - scores[i] <= 2) return true;<br /> }<br /> return false;<br />}Nicknoreply@blogger.comtag:blogger.com,1999:blog-5872623838295077986.post-89679412284541785032014-08-19T12:55:51.591-07:002014-08-19T12:55:51.591-07:00Couldn't you take out the "if (scores.len...Couldn't you take out the "if (scores.length < 3) return false;" since if the length is less than 3, the "if" statement in the loop would never execute and thus end up hitting the final "return false;"<br />Also, the array is in ascending order, so if "scores[i+2]-scores[i] <=2", "scores[i+2]-[i+1]" would automatically be true since the list is sorted.Anonymousnoreply@blogger.com