2021年3月30日星期二

Check If a Java array is a Palindrome from a certain element

I wrote a simple method to check if an array is a palindrome from a certain element. The problem is, I don't get any output from the method. There must be something wrong. Here is the code:

public static boolean isPalindrome(int[] arr, int start)  {            if (arr.length == 0) { //empty array is a palindrome          return true;      }        //loop from start to the end of array      for (int i = start; i<arr.length; i++)       {          //loop from end of array to start          for (int j =arr.length - 1; j >= start; j -= 1)          {              if (arr[i] != arr[j]) {              return false;                 }              }          }              return true;        }  
https://stackoverflow.com/questions/66793250/check-if-a-java-array-is-a-palindrome-from-a-certain-element March 25, 2021 at 12:47PM

没有评论:

发表评论