Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean sim(int[] a, int i) {
- // check if I reached the middle of the array
- if (i == a.length / 2 || i + 1 == a.length) {
- // if array's length is even, need to check the two mid cells
- if (a.length % 2 == 0)
- return a[i] == a[i - 1] ? true : false;
- // if odd, there's only one cell in the middle, So I don't need to check anything.
- return true;
- } else {
- return a[i] == a[a.length - i - 1] ? true && sim(a, i + 1) : false && sim(a, i + 1);
- }
- }
- public static void main(String[] args) {
- int[] a = { 1, 2, 4, 2, 1 };
- System.out.println(sim(a, 0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement