In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "leetcode linked list how to solve the palindrome linked list problem", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn "leetcode linked list how to solve the palindrome linked list problem" this article.
Please determine whether a linked list is a palindromic linked list. Example 1: input: 1-> 2 output: false example 2: input: 1-> 2-> 2-> 1 output: true Advanced: can you use O (n) time complexity and O (1) space complexity to solve this problem? Source: LeetCode link: https://leetcode-cn.com/problems/palindrome-linked-list copyright belongs to the collar buckle network. For commercial reprint, please contact official authorization. For non-commercial reprint, please indicate the source. Answer the question / Definition for singly-linked list. * public class ListNode {* int val; * ListNode next; * ListNode (int x) {val = x;} *} * / class Solution {public boolean isPalindrome (ListNode head) {if (head = = null) {return true;} Stack stack = new Stack (); ListNode cursor = head; while (cursor! = null) {stack.push (cursor.val) Cursor = cursor.next;} cursor = head; while (cursor! = null) {int val = (int) stack.pop (); if (val! = cursor.val) {return false;} cursor = cursor.next;} return true }} above are all the contents of the article "how to solve the palindrome linked list problem of leetcode linked list". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.