/*
 * Copyright (C) 2014 Pedro Vicente Gómez Sánchez.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.pedrovgs.problem62;

/**
 * Implement a function to check if a linked list is a palindrome,
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
public class PalindromeList {

}

@@ -645,16 +645,121 @@
 lem62;%0A%0A
+import com.github.pedrovgs.linkedlist.ListNode;%0Aimport com.github.pedrovgs.problem22.ReverseLinkedList;%0A%0A
 /**%0A * I
@@ -899,10 +899,1146 @@
 List %7B%0A%0A
+  private final ReverseLinkedList reverseLinkedList;%0A%0A  public PalindromeList() %7B%0A    this.reverseLinkedList = new ReverseLinkedList();%0A  %7D%0A%0A  /**%0A   * Iterative algorithm to solve this problem. If a List is a palindrome the reverse list has to%0A   * be equals to the original list. This is the base of this algorithm. The complexity order is%0A   * the same than reverse list algorithm - O(N) in time terms - because%0A   * this is the most expensive operation. In space terms, the complexity order of this algorithm%0A   * is%0A   * O(N).%0A   */%0A  public boolean checkReversing(ListNode list) %7B%0A    validateInput(list);%0A%0A    ListNode%3CInteger%3E reversedList = reverseLinkedList.reverseIterative(list);%0A%0A    boolean isPalindrome = true;%0A    while (list != null) %7B%0A      isPalindrome = list.equals(reversedList);%0A      if (!isPalindrome) %7B%0A        break;%0A      %7D%0A      reversedList = reversedList.getNext();%0A      list = list.getNext();%0A    %7D%0A    return isPalindrome;%0A  %7D%0A%0A  private void validateInput(ListNode%3CInteger%3E list) %7B%0A    if (list == null) %7B%0A      throw new IllegalArgumentException(%22You can't pass a null list as parameter.%22);%0A    %7D%0A  %7D%0A
 %7D%0A

Add solution to problem 62