diff --git a/LeetCode/src/main/java/com/code/leet/study/t20210208/IsPalindrome.java b/LeetCode/src/main/java/com/code/leet/study/t20210208/IsPalindrome.java new file mode 100644 index 0000000..f1e724b --- /dev/null +++ b/LeetCode/src/main/java/com/code/leet/study/t20210208/IsPalindrome.java @@ -0,0 +1,33 @@ +package com.code.leet.study.t20210208; + +import com.code.leet.entiy.ListNode; + +/** + * 编写一个函数,检查输入的链表是否是回文的。 + */ +public class IsPalindrome { + ListNode temp; + + /** + * 面试题 02.06. 回文链表 + */ + public boolean isPalindrome(ListNode head) { + temp = head; + return isP(head); + } + + public boolean isP(ListNode curNode) { + if (curNode != null) { + if (isP(curNode.next)) { + if (curNode.val != temp.val) { + return false; + } + temp = temp.next; + return true; + } else { + return false; + } + } + return true; + } +}