文件名称:leetcode147-algorithm:leetcode
文件大小:48KB
文件格式:ZIP
更新时间:2024-07-20 07:32:56
系统开源
leetcode147 [TOC] 一、线性表 二、链表 单向链表结构定义如下: struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; 1、翻转链表 递归解法 设置递归函数的返回值为翻转后链表的首节点 递归终止条件为空节点或节点长度为1 实现代码如下: ListNode* reverse ( ListNode* head ) { if ( ! head || head->next == NULL ) return head; ListNode* newHead = reverse ( head->next ); head->next->next = head; head->next = NULL; return newHead; } 非递归解法 尾插法,将原本的节点通过尾插法不断的加入新节点 实现代码如下: ListNode* reverse ( ListNode* head ) { if ( ! head || head->next == NULL ) ListNod
【文件预览】:
algorithm-master
----divide and conquer()
--------leetcode241.cpp(1KB)
--------leetcode17.10.cpp(849B)
----.vscode()
--------launch.json(1KB)
--------c_cpp_properties.json(1KB)
--------settings.json(616B)
--------tasks.json(480B)
----tree()
--------leetcode04.06.cpp(291B)
--------leetcode96.cpp(350B)
--------leetcode98.cpp(735B)
--------leetcode104.cpp(758B)
--------leetcode235.cpp(510B)
--------leetcode110.cpp(1KB)
--------leetcode04.04.cpp(652B)
--------leetcode04.05.cpp(672B)
--------leetcode102.cpp(1KB)
--------leetcode95.cpp(1KB)
--------leetcode222.cpp(333B)
--------leetcode107.cpp(2KB)
----graph()
--------leetcode133.cpp(0B)
--------leetcode802.cpp(793B)
--------leetcode1162.cpp(2KB)
--------leetcode210.cpp(1KB)
--------leetcode04.01.cpp(2KB)
--------leetcode207.cpp(2KB)
----README.md(22KB)
----stack()
--------leetcode20.cpp(907B)
--------leetcode150.cpp(923B)
----backtracking()
--------leetcode47.cpp(1KB)
--------leetcode22.cpp(850B)
--------leetcode216.cpp(1KB)
--------leetcode46.cpp(1KB)
--------leetcode39.cpp(1KB)
--------leetcode52.cpp(1KB)
--------leetcode131.cpp(1KB)
--------leetcode40.cpp(2KB)
--------leetcode77.cpp(929B)
--------leetcode78.cpp(971B)
--------leetcode90.cpp(1KB)
--------leetcode51.cpp(1KB)
----binary_search()
--------leetcode1011.cpp(1KB)
--------leetcode1283.cpp(485B)
----dynamic_programming()
--------leetcode152.cpp(1KB)
--------leetcode72.cpp(1KB)
--------LCS.cpp(738B)
--------leetcode120.cpp(1KB)
--------leetcode139.cpp(1KB)
--------leetcode63.cpp(906B)
--------leetcode300.cpp(937B)
--------leetcode516.cpp(892B)
--------leetcode221.cpp(1KB)
--------leetcode5.cpp(1KB)
--------backpack.cpp(835B)
----link()
--------leetcode141.cpp(515B)
--------leetcode21.cpp(714B)
--------leetcode83.cpp(493B)
--------leetcode92.cpp(909B)
--------leetcode143.cpp(2KB)
--------leetcode148.cpp(2KB)
--------leetcode109.cpp(1KB)
--------leetcode147.cpp(2KB)
--------leetcode2.cpp(970B)
--------leetcode25.cpp(2KB)
--------leetcode234.cpp(565B)
--------leetcode86.cpp(1KB)
--------leetcode206.cpp(822B)
--------leetcode237.cpp(223B)
--------leetcode61.cpp(884B)
--------leetcode203.cpp(513B)
--------leetcode142.cpp(732B)
--------leetcode82.cpp(2KB)
--------leetcode24.cpp(1KB)
--------leetcode160.cpp(421B)
--------leetcode19.cpp(818B)
--------leetcode23.cpp(1KB)