Created
January 28, 2023 23:08
-
-
Save pjastr/e1b99abdf4fe47f9556701aa5348a527 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.LocalDate; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Integer[] intArray1 = {1, 2, 3, 4, 5}; | |
| Integer[] intArray2 = {1, 2, 3, 2, 1}; | |
| LocalDate[] dateArray1 = {LocalDate.of(2020, 1, 1), LocalDate.of(2020, 2, 1), LocalDate.of(2020, 3, 1)}; | |
| LocalDate[] dateArray2 = {LocalDate.of(2020, 1, 1), LocalDate.of(2020, 2, 1), LocalDate.of(2020, 1, 1)}; | |
| System.out.println(ArrayUtil.jestPalindromem(intArray1)); // false | |
| System.out.println(ArrayUtil.jestPalindromem(intArray2)); // true | |
| System.out.println(ArrayUtil.jestPalindromem(dateArray1)); // false | |
| System.out.println(ArrayUtil.jestPalindromem(dateArray2)); // true | |
| } | |
| } | |
| class ArrayUtil { | |
| public static <T extends Comparable<T>> boolean jestPalindromem(T[] array) { | |
| int left = 0; | |
| int right = array.length - 1; | |
| while (left < right) { | |
| if (!array[left].equals(array[right])) { | |
| return false; | |
| } | |
| left++; | |
| right--; | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment