LinkedList:检查链表是否回文

public static boolean test5(Node node) {
        Stack stack = new Stack();
        Node head = node;
        while (head!=null) {
            stack.push(head.value);
            head = head.next;
        }
        
        while (!stack.isEmpty()) {
            if (stack.pop()!=node.value) {
                return false;
            }
            node = node.next;
        }
        
        return true;
    }

你可能感兴趣的:(LinkedList:检查链表是否回文)