Problem:
Given an array of scores, return true if each score is equal or greater than the one before. The array will be length 2 or more.
scoresIncreasing({1, 3, 4}) → true
scoresIncreasing({1, 3, 2}) → false
scoresIncreasing({1, 1, 4}) → true
Solution:
public boolean scoresIncreasing(int[] scores) { boolean match = false; for (int i = 0; i < scores.length-1; i++) { if (scores[i+1] >= scores[i]) match = true; else return false; } return match; }
public boolean scoresIncreasing(int[] nums) {
ReplyDeletefor (int i = 0; i < nums.length; i++) {
if(i+1nums[i+1]){
return false;
}
}
}
return true;
}
public boolean scoresIncreasing(int[] nums) {
ReplyDeletefor (int i = 0; i < nums.length; i++) {
if(i+1nums[i+1]){
return false;
}
}
}
return true;
}
Don't know why didn't my code uploaded successfully that's why i am trying it for third time........
ReplyDeletepublic boolean scoresIncreasing(int[] scores) {
for (int i = 0; i < scores.length; i++) {
if(i+1scores[i+1]){
return false;
}
}
}
return true;
}
Still not done...Please correct it from line 3
Deleteif(i+1scores[i+1]){
return false;}}
public boolean scoresIncreasing(int[] scores) {
ReplyDeletefor(int i = 0; i< scores.length-1;i++){
if(scores[i]>scores[i+1]){
return false;
}
}
return true;
}
won't the code return b at the end regardless of if the else statement executed or not?
ReplyDeletewouldn't the return b at the end execute regardless if the else statement executed or not?
ReplyDeleteint holder = scores[0];
ReplyDeleteint tick = 0;
for( int i = 0; i < scores.length; i++) {
if(scores[i] >= holder) {
holder = scores[i];
tick++;
}
}
if(tick == scores.length){
return true;
} else {
return false;
}
for (int i = 0; i < scores.length - 1; i++)
ReplyDeleteif (scores[i] > scores[i+1])
return false;
return true;
public boolean scoresIncreasing(int[] scores)
ReplyDelete{
boolean greater = false;
for(int i = scores.length-1; i > 0; i--)
{
if(scores[i] >= scores[i-1]) greater = true;
else return greater = false;
}
return greater;
}
public boolean scoresIncreasing(int[] scores) {
ReplyDeletefor(int i=0 ;iscores[i+1])
return false;
}
return true;
}