LeetCode OJ:Palindrome Linked List(回文链表判断) | 寵物協尋網
![LeetCode OJ:Palindrome Linked List(回文链表判断)](https://i.imgur.com/voy7JL0.jpg)
2015年10月8日—Givenasinglylinkedlist,determineifitisapalindrome.Followup:CouldyoudoitinO(n)timeandO(1)space?判断一个链表是否为回文 ...
![LeetCode OJ:Palindrome Linked List(回文链表判断)](https://i.imgur.com/voy7JL0.jpg)
Given a singly linked list, determine if it is a palindrome.
Follow up: Could you do it in O(n) time and O(1) space?
判断一个链表是否为回文链表,有很多方法都可以进行判断,可以先遍历链表然后将值全部存储到vector之中,也可以遍历链表然后将list中的值都压倒堆栈中再和List进行比较,
但是想要达到题目上面的 时间复杂度为O(n),而空间复杂度为O(1)还要用到递归:
首先是不用递归的方法(使用一个栈):
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution { 10 public: 11 bool isPalindrome(ListNode* head) { 12 ListNode * tmpHead = head; 13 stack<int> lt; 14 while (tmpHead){ 15 lt.push(tmpHead->val); 16 tmpHead = tmpHead->next; 17 } 18 19 while (!lt.empty()){ 20 if (head->val != lt.top()) return false; 21 lt.pop(); 22 head = head->next; 23 } 24 retur...Eclipses visible in Irwin, Iowa | 寵物協尋網
Which upcoming lunar and solar eclipses are visible in Irwin, Iowa, USA and what do they look like? Read More
LeetCode OJ:Palindrome Linked List(回文链表判断) | 寵物協尋網
2015年10月8日 — Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 判断一个链表是否为回文 ... Read More
SML-P12UTT86R Rohm Semiconductor | 寵物協尋網
SML-P12UTT86R ; RoHS Status, ROHS3 Compliant ; Moisture Sensitivity Level (MSL), 3 (168 Hours) ; REACH Status, REACH Unaffected ; ECCN, EAR99. Read More
SML | 寵物協尋網
SML-P12UTT86R ; RoHS Status, ROHS3 Compliant ; Moisture Sensitivity Level (MSL), 3 (168 Hours) ; REACH Status, REACH Unaffected ; ECCN, EAR99. Read More
SML-P12UTT86R Rohm Semiconductor | 寵物協尋網
Description. RoHS Status, ROHS3 Compliant. Moisture Sensitivity Level (MSL), 3 (168 Hours). REACH Status, REACH Unaffected. ECCN, EAR99. HTSUS, 8541.41.0000 ... Read More
US4862236A | 寵物協尋網
A semiconducting photodiode for detecting light at a predetermined wavelength includes, according to this invention, a first semiconducting region having a ... Read More
區塊鏈儲存項目KYVE推出激勵測試網Mission Korellia | 寵物協尋網
2022年5月2日 — 5月2日消息,區塊鏈儲存項目KYVE 宣布推出激勵測試網Mission Korellia。KYVE Network 表示,該項目將使用從激勵測試網收集的所有數據來改進KYVE 網路 ... Read More
天风证券股份有限公司关于苏州天华超净科技股份有限公司向 ... | 寵物協尋網
2021年10月22日 — 1,215,559 6个月. 2 宁德时代新能源科技股份有限公司. 4,862,236 6个月. 3 徐学青. 810,372 6个月. 4. 长江晨道(湖北)新能源产业投资合伙企业(有限. Read More
相關資訊整理
哈士奇-遺失 - 灰白長毛 6965938
於「桃縣新屋鄉下田村7號〔住家〕」遺失的哈士奇,以下提供飼主姓名、電話、Email,以及晶片號碼、寵物外觀及特徵等資訊,如...