现给定一个链表ListNode* pHead,定义bool代表链表是否为回文,请编写程序。 测试样例: {1,2,3,2,1} 返回:true {1,2,3,2,3} 返回:false
加载中...
import java.util.*; /* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Palindrome { public boolean isPalindrome(ListNode pHead) { // write code here } }
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/ class Palindrome { public: bool isPalindrome(ListNode* pHead) { // write code here } };
# -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Palindrome: def isPalindrome(self, pHead): # write code here
/* public class ListNode { public int val; public ListNode next; public ListNode (int x) { val = x; } }*/ class Palindrome { public bool isPalindrome(ListNode pHead) { // write code here } }