Merge pull request #2186 from jinbudaily/master

更新 链表章节 排版格式
This commit is contained in:
程序员Carl
2023-07-19 10:33:28 +08:00
committed by GitHub
10 changed files with 159 additions and 140 deletions

View File

@ -7,7 +7,7 @@
## 19.删除链表的倒数第N个节点
# 19.删除链表的倒数第N个节点
[力扣题目链接](https://leetcode.cn/problems/remove-nth-node-from-end-of-list/)
@ -31,11 +31,13 @@
输入head = [1,2], n = 1
输出:[1]
## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[链表遍历学清楚! | LeetCode19.删除链表倒数第N个节点](https://www.bilibili.com/video/BV1vW4y1U7Gf),相信结合视频再看本篇题解,更有助于大家对链表的理解。**
## 思路
《代码随想录》算法公开课:[链表遍历学清楚! | LeetCode19.删除链表倒数第N个节点](https://www.bilibili.com/video/BV1vW4y1U7Gf),相信结合视频在看本篇题解,更有助于大家对链表的理解。
双指针的经典应用如果要删除倒数第n个节点让fast移动n步然后让fast和slow同时移动直到fast指向链表末尾。删掉slow所指向的节点就可以了。
@ -93,7 +95,7 @@ public:
## 其他语言版本
java:
### Java:
```java
public ListNode removeNthFromEnd(ListNode head, int n){
@ -120,7 +122,8 @@ public ListNode removeNthFromEnd(ListNode head, int n){
}
```
Python:
### Python:
```python
# Definition for singly-linked list.
# class ListNode:
@ -151,7 +154,8 @@ class Solution:
return dummy_head.next
```
Go:
### Go:
```Go
/**
* Definition for singly-linked list.
@ -178,7 +182,7 @@ func removeNthFromEnd(head *ListNode, n int) *ListNode {
}
```
JavaScript:
### JavaScript:
```js
/**
@ -198,7 +202,7 @@ var removeNthFromEnd = function(head, n) {
return ret.next;
};
```
TypeScript:
### TypeScript:
版本一(快慢指针法):
@ -263,7 +267,7 @@ function removeNthFromEnd(head: ListNode | null, n: number): ListNode | null {
};
```
Kotlin:
### Kotlin:
```Kotlin
fun removeNthFromEnd(head: ListNode?, n: Int): ListNode? {
@ -284,7 +288,8 @@ fun removeNthFromEnd(head: ListNode?, n: Int): ListNode? {
}
```
Swift
### Swift
```swift
func removeNthFromEnd(_ head: ListNode?, _ n: Int) -> ListNode? {
if head == nil {
@ -309,8 +314,8 @@ func removeNthFromEnd(_ head: ListNode?, _ n: Int) -> ListNode? {
}
```
### PHP:
PHP:
```php
function removeNthFromEnd($head, $n) {
// 设置虚拟头节点
@ -332,7 +337,8 @@ function removeNthFromEnd($head, $n) {
}
```
Scala:
### Scala:
```scala
object Solution {
def removeNthFromEnd(head: ListNode, n: Int): ListNode = {
@ -356,7 +362,8 @@ object Solution {
}
```
Rust:
### Rust:
```rust
impl Solution {
pub fn remove_nth_from_end(head: Option<Box<ListNode>>, mut n: i32) -> Option<Box<ListNode>> {
@ -377,7 +384,8 @@ impl Solution {
}
}
```
C语言
### C
```c
/**c语言单链表的定义
* Definition for singly-linked list.
@ -412,7 +420,8 @@ struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
```
C#
### C#
```csharp
public class Solution {
public ListNode RemoveNthFromEnd(ListNode head, int n) {

View File

@ -5,7 +5,7 @@
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
## 24. 两两交换链表中的节点
# 24. 两两交换链表中的节点
[力扣题目链接](https://leetcode.cn/problems/swap-nodes-in-pairs/)
@ -16,9 +16,11 @@
<img src='https://code-thinking.cdn.bcebos.com/pics/24.%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9-%E9%A2%98%E6%84%8F.jpg' width=600 alt='24.两两交换链表中的节点-题意'> </img></div>
## 思路
## 算法公开课
《代码随想录》算法公开课:[帮你把链表细节学清楚! | LeetCode24. 两两交换链表中的节点](https://www.bilibili.com/video/BV1YT411g7br),相信结合视频看本篇题解,更有助于大家对链表的理解。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[帮你把链表细节学清楚! | LeetCode24. 两两交换链表中的节点](https://www.bilibili.com/video/BV1YT411g7br),相信结合视频看本篇题解,更有助于大家对本题的理解**
## 思路
这道题目正常模拟就可以了。
@ -88,7 +90,8 @@ public:
## 其他语言版本
C:
### C:
```c
/**
* Definition for singly-linked list.
@ -132,7 +135,7 @@ struct ListNode* swapPairs(struct ListNode* head){
}
```
Java
### Java
```Java
// 递归版本
@ -176,7 +179,8 @@ class Solution {
}
```
Python
### Python
```python
# 递归版本
# Definition for singly-linked list.
@ -226,7 +230,8 @@ class Solution:
```
Go
### Go
```go
func swapPairs(head *ListNode) *ListNode {
dummy := &ListNode{
@ -262,7 +267,8 @@ func swapPairs(head *ListNode) *ListNode {
}
```
Javascript:
### Javascript:
```javascript
var swapPairs = function (head) {
let ret = new ListNode(0, head), temp = ret;
@ -277,7 +283,7 @@ var swapPairs = function (head) {
};
```
TypeScript
### TypeScript
```typescript
function swapPairs(head: ListNode | null): ListNode | null {
@ -296,7 +302,7 @@ function swapPairs(head: ListNode | null): ListNode | null {
};
```
Kotlin:
### Kotlin:
```kotlin
fun swapPairs(head: ListNode?): ListNode? {
@ -316,7 +322,8 @@ fun swapPairs(head: ListNode?): ListNode? {
}
```
Swift:
### Swift:
```swift
func swapPairs(_ head: ListNode?) -> ListNode? {
if head == nil || head?.next == nil {
@ -337,7 +344,8 @@ func swapPairs(_ head: ListNode?) -> ListNode? {
return dummyHead.next
}
```
Scala:
### Scala:
```scala
// 虚拟头节点
object Solution {
@ -361,7 +369,8 @@ object Solution {
}
```
PHP:
### PHP:
```php
//虚拟头结点
function swapPairs($head) {
@ -404,7 +413,7 @@ function swapPairs($head)
}
```
Rust:
### Rust:
```rust
// 虚拟头节点

View File

@ -70,7 +70,7 @@ public:
## 其他语言版本
### Java
### Java:
```java
public class Solution {
@ -90,7 +90,7 @@ public class Solution {
}
```
### Python
### Python:
```python
class Solution:
@ -105,7 +105,7 @@ class Solution:
return False
```
### Go
### Go:
```go
func hasCycle(head *ListNode) bool {
@ -125,7 +125,7 @@ func hasCycle(head *ListNode) bool {
}
```
### JavaScript
### JavaScript:
```js
var hasCycle = function(head) {
@ -141,7 +141,7 @@ var hasCycle = function(head) {
};
```
### TypeScript
### TypeScript:
```typescript
function hasCycle(head: ListNode | null): boolean {
@ -163,3 +163,4 @@ function hasCycle(head: ListNode | null): boolean {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -11,7 +11,7 @@
> 找到有没有环已经很不容易了,还要让我找到环的入口?
## 142.环形链表II
# 142.环形链表II
[力扣题目链接](https://leetcode.cn/problems/linked-list-cycle-ii/)
@ -24,9 +24,11 @@
![循环链表](https://code-thinking-1253855093.file.myqcloud.com/pics/20200816110112704.png)
## 思路
## 算法公开课
《代码随想录》算法公开课:[把环形链表讲清楚!| LeetCode:142.环形链表II](https://www.bilibili.com/video/BV1if4y1d7ob),相信结合视频在看本篇题解,更有助于大家对链表的理解。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[把环形链表讲清楚!| LeetCode:142.环形链表II](https://www.bilibili.com/video/BV1if4y1d7ob),相信结合视频在看本篇题解,更有助于大家对链表的理解。**
## 思路
这道题目,不仅考察对链表的操作,而且还需要一些数学运算。
@ -148,7 +150,7 @@ public:
* 时间复杂度: O(n)快慢指针相遇前指针走的次数小于链表长度快慢指针相遇后两个index指针走的次数也小于链表长度总体为走的次数小于 2n
* 空间复杂度: O(1)
## 补充
### 补充
在推理过程中,大家可能有一个疑问就是:**为什么第一次在环中相遇slow的 步数 是 x+y 而不是 x + 若干环的长度 + y 呢?**
@ -190,8 +192,7 @@ public:
## 其他语言版本
Java
### Java
```java
public class Solution {
@ -217,8 +218,7 @@ public class Solution {
}
```
Python
### Python
```python
版本一快慢指针法
@ -270,7 +270,7 @@ class Solution:
return None
```
Go
### Go
```go
func detectCycle(head *ListNode) *ListNode {
@ -290,7 +290,7 @@ func detectCycle(head *ListNode) *ListNode {
}
```
javaScript
### JavaScript
```js
// 两种循环实现方式
@ -334,7 +334,7 @@ var detectCycle = function(head) {
};
```
TypeScript
### TypeScript
```typescript
function detectCycle(head: ListNode | null): ListNode | null {
@ -356,7 +356,7 @@ function detectCycle(head: ListNode | null): ListNode | null {
};
```
Swift:
### Swift:
```swift
class Solution {
@ -391,7 +391,7 @@ extension ListNode: Equatable {
}
```
C
### C
```c
ListNode *detectCycle(ListNode *head) {
@ -410,7 +410,7 @@ ListNode *detectCycle(ListNode *head) {
}
```
Scala:
### Scala:
```scala
object Solution {
@ -437,7 +437,7 @@ object Solution {
}
```
C#:
### C#:
```CSharp
public class Solution
{

View File

@ -27,14 +27,12 @@
输入head = [7,7,7,7], val = 7
输出:[]
# 算法公开课
## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[链表基础操作| LeetCode203.移除链表元素](https://www.bilibili.com/video/BV18B4y1s7R9),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
# 思路
为了方便大家理解,我特意录制了视频:[链表基础操作| LeetCode203.移除链表元素](https://www.bilibili.com/video/BV18B4y1s7R9),结合视频在看本题解,事半功倍。
## 思路
这里以链表 1 4 2 4 来举例移除元素4。
@ -90,9 +88,6 @@
最后呢在题目中return 头结点的时候,别忘了 `return dummyNode->next;` 这才是新的头结点
# C++代码
**直接使用原来的链表来进行移除节点操作:**
```CPP
@ -159,7 +154,7 @@ public:
## 其他语言版本
C:
### C:
用原来的链表操作:
```c
@ -227,7 +222,7 @@ struct ListNode* removeElements(struct ListNode* head, int val){
}
```
Java
### Java
```java
/**
@ -308,7 +303,7 @@ public ListNode removeElements(ListNode head, int val) {
}
```
Python
### Python
```python
版本一虚拟头节点法
@ -334,7 +329,7 @@ class Solution:
```
Go
### Go
```go
/**
@ -359,7 +354,7 @@ func removeElements(head *ListNode, val int) *ListNode {
}
```
javaScript:
### JavaScript:
```js
/**
@ -381,7 +376,7 @@ var removeElements = function(head, val) {
};
```
TypeScript:
### TypeScript:
版本一(在原链表上直接删除):
@ -437,7 +432,7 @@ function removeElements(head: ListNode | null, val: number): ListNode | null {
};
```
Swift
### Swift
```swift
/**
@ -465,7 +460,7 @@ func removeElements(_ head: ListNode?, _ val: Int) -> ListNode? {
}
```
PHP:
### PHP:
```php
/**
@ -493,7 +488,7 @@ func removeElements(head *ListNode, val int) *ListNode {
}
```
RUST:
### Rust:
```rust
// Definition for singly-linked list.
@ -531,7 +526,7 @@ impl Solution {
}
```
Scala:
### Scala:
```scala
/**
@ -564,7 +559,7 @@ object Solution {
}
```
Kotlin:
### Kotlin:
```kotlin
/**
@ -600,7 +595,8 @@ class Solution {
}
```
C#
### C#
```CSharp
/**
* Definition for singly-linked list.
@ -639,3 +635,4 @@ public class Solution
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -17,14 +17,12 @@
输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
# 算法公开课
## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[帮你拿下反转链表 | LeetCode206.反转链表](https://www.bilibili.com/video/BV1nB4y1i7eL),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
# 思路
本题我录制了B站视频[帮你拿下反转链表 | LeetCode206.反转链表](https://www.bilibili.com/video/BV1nB4y1i7eL),相信结合视频在看本篇题解,更有助于大家对链表的理解。
## 思路
如果再定义一个新的链表,实现链表元素的反转,其实这是对内存空间的浪费。
@ -51,9 +49,7 @@
最后cur 指针已经指向了null循环结束链表也反转完毕了。 此时我们return pre指针就可以了pre指针就指向了新的头结点。
# C++代码
## 双指针法
### 双指针法
```CPP
class Solution {
public:
@ -76,7 +72,7 @@ public:
* 时间复杂度: O(n)
* 空间复杂度: O(1)
## 递归法
### 递归法
递归法相对抽象一些但是其实和双指针法是一样的逻辑同样是当cur为空的时候循环结束不断将cur指向pre的过程。
@ -137,8 +133,8 @@ public:
## 其他语言版本
### Java
Java
```java
// 双指针
class Solution {
@ -198,7 +194,8 @@ class Solution {
}
```
Python
### Python
```python
版本一双指针法
# Definition for singly-linked list.
@ -219,8 +216,6 @@ class Solution:
return pre
```
Python递归法
```python
版本二递归法
# Definition for singly-linked list.
@ -242,7 +237,7 @@ class Solution:
Go
### Go
```go
//双指针
@ -273,7 +268,7 @@ func help(pre, head *ListNode)*ListNode{
}
```
javaScript:
### JavaScript:
```js
/**
@ -328,7 +323,7 @@ var reverseList = function(head) {
};
```
TypeScript:
### TypeScript:
```typescript
// 双指针法
@ -376,7 +371,7 @@ function reverseList(head: ListNode | null): ListNode | null {
};
```
Ruby:
### Ruby:
```ruby
# 双指针
@ -421,7 +416,8 @@ def reverse(pre, cur)
end
```
Kotlin:
### Kotlin:
```Kotlin
fun reverseList(head: ListNode?): ListNode? {
var pre: ListNode? = null
@ -471,7 +467,8 @@ class Solution {
}
```
Swift
### Swift
```swift
/// 双指针法 (迭代)
/// - Parameter head: 头结点
@ -508,8 +505,9 @@ func reverse(pre: ListNode?, cur: ListNode?) -> ListNode? {
}
```
C:
### C:
双指针法:
```c
struct ListNode* reverseList(struct ListNode* head){
//保存cur的下一个结点
@ -549,7 +547,8 @@ struct ListNode* reverseList(struct ListNode* head){
PHP:
### PHP:
```php
// 双指针法:
function reverseList($head) {
@ -565,8 +564,9 @@ function reverseList($head) {
}
```
Scala:
### Scala:
双指针法:
```scala
object Solution {
def reverseList(head: ListNode): ListNode = {
@ -601,7 +601,7 @@ object Solution {
}
```
Rust:
### Rust:
双指针法:
```rust
@ -640,7 +640,7 @@ impl Solution {
}
}
```
C#:
### C#:
三指针法, 感觉会更直观:
```cs
@ -677,11 +677,11 @@ public class LinkNumbers
}
```
## 其他解法
### 使用虚拟头结点解决链表反转
## 使用虚拟头结点解决链表翻转
> 使用虚拟头结点,通过头插法实现链表的翻转(不需要栈)
> 使用虚拟头结点,通过头插法实现链表的反转(不需要栈)
```java
// 迭代方法:增加虚头结点,使用头插法实现链表翻转
@ -704,7 +704,7 @@ public static ListNode reverseList1(ListNode head) {
## 使用栈解决反转链表的问题
### 使用栈解决反转链表的问题
* 首先将所有的结点入栈
* 然后创建一个虚拟虚拟头结点让cur指向虚拟头结点。然后开始循环出栈每出来一个元素就把它加入到以虚拟头结点为头结点的链表当中最后返回即可。
@ -743,4 +743,3 @@ public ListNode reverseList(ListNode head) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -25,12 +25,12 @@
![707示例](https://code-thinking-1253855093.file.myqcloud.com/pics/20200814200558953.png)
# 算法公开课
## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[帮你把链表操作学个通透LeetCode707.设计链表](https://www.bilibili.com/video/BV1FU4y1X7WD),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
# 思路
## 思路
如果对链表的基础知识还不太懂,可以看这篇文章:[关于链表,你该了解这些!](https://programmercarl.com/链表理论基础.html)
@ -58,8 +58,6 @@
下面采用的设置一个虚拟头结点(这样更方便一些,大家看代码就会感受出来)。
## 代码
```CPP
class MyLinkedList {
public:
@ -167,7 +165,8 @@ private:
## 其他语言版本
C:
### C:
```C
typedef struct MyLinkedList {
int val;
@ -291,7 +290,8 @@ void myLinkedListFree(MyLinkedList* obj) {
*/
```
Java
### Java
```Java
//单链表
class ListNode {
@ -487,7 +487,8 @@ class MyLinkedList {
*/
```
Python
### Python
```python
版本一单链表法
class ListNode:
@ -661,7 +662,7 @@ class MyLinkedList:
# obj.deleteAtIndex(index)
```
Go
### Go
```go
//单链表实现
@ -915,7 +916,7 @@ func (this *MyLinkedList) DeleteAtIndex(index int) {
}
```
javaScript:
### JavaScript:
```js
@ -1055,7 +1056,8 @@ MyLinkedList.prototype.deleteAtIndex = function(index) {
*/
```
TypeScript:
### TypeScript:
```TypeScript
class ListNode {
public val: number;
@ -1173,7 +1175,8 @@ class MyLinkedList {
}
```
Kotlin:
### Kotlin:
```kotlin
class MyLinkedList {
@ -1241,8 +1244,7 @@ class MyLinkedList {
}
```
Swift:
### Swift:
```swift
class MyLinkedList {
@ -1323,7 +1325,8 @@ class MyLinkedList {
}
```
Scala:
### Scala:
```scala
class ListNode(_x: Int = 0, _next: ListNode = null) {
var next: ListNode = _next
@ -1393,7 +1396,7 @@ class MyLinkedList() {
}
```
Rust:
### Rust:
```rust
#[derive(Debug)]
@ -1486,4 +1489,3 @@ impl MyLinkedList {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -3,7 +3,7 @@
<img src="../pics/训练营.png" width="1000"/>
</a>
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
# 链表总结篇
## 链表的理论基础
@ -68,7 +68,7 @@
[链表:链表相交](https://programmercarl.com/面试题02.07.链表相交.html)使用双指针来找到两个链表的交点(引用完全相同,即:内存地址完全相同的交点)
## 环形链表
### 环形链表
在[链表:环找到了,那入口呢?](https://programmercarl.com/0142.环形链表II.html)中,讲解了在链表如何找环,以及如何找环的入口位置。
@ -100,3 +100,4 @@
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -16,15 +16,15 @@
如图所示:
![链表1](https://code-thinking-1253855093.file.myqcloud.com/pics/20200806194529815.png)
# 链表的类型
## 链表的类型
接下来说一下链表的几种类型:
## 单链表
### 单链表
刚刚说的就是单链表。
## 双链表
### 双链表
单链表中的指针域只能指向节点的下一个节点。
@ -35,7 +35,7 @@
如图所示:
![链表2](https://code-thinking-1253855093.file.myqcloud.com/pics/20200806194559317.png)
## 循环链表
### 循环链表
循环链表,顾名思义,就是链表首尾相连。
@ -44,7 +44,7 @@
![链表4](https://code-thinking-1253855093.file.myqcloud.com/pics/20200806194629603.png)
# 链表的存储方式
## 链表的存储方式
了解完链表的类型,再来说一说链表在内存中的存储方式。
@ -60,7 +60,7 @@
这个链表起始节点为2 终止节点为7 各个节点分布在内存的不同地址空间上,通过指针串联在一起。
# 链表的定义
## 链表的定义
接下来说一说链表的定义。
@ -100,9 +100,9 @@ head->val = 5;
所以如果不定义构造函数使用默认构造函数的话,在初始化的时候就不能直接给变量赋值!
# 链表的操作
## 链表的操作
## 删除节点
### 删除节点
删除D节点如图所示
@ -116,7 +116,7 @@ head->val = 5;
其他语言例如Java、Python就有自己的内存回收机制就不用自己手动释放了。
## 添加节点
### 添加节点
如图所示:
@ -126,7 +126,7 @@ head->val = 5;
但是要注意要是删除第五个节点需要从头节点查找到第四个节点通过next指针进行删除操作查找的时间复杂度是O(n)。
# 性能分析
## 性能分析
再把链表的特性和数组的特性进行一个对比,如图所示:
@ -143,8 +143,7 @@ head->val = 5;
## 其他语言版本
Java
### Java
```java
public class ListNode {
@ -171,7 +170,7 @@ public class ListNode {
}
```
JavaScript:
### JavaScript:
```javascript
class ListNode {
@ -184,7 +183,7 @@ class ListNode {
}
```
TypeScript:
### TypeScript:
```typescript
class ListNode {
@ -197,7 +196,7 @@ class ListNode {
}
```
Python
### Python
```python
class ListNode:
@ -206,7 +205,7 @@ class ListNode:
self.next = next
```
Go
### Go
```go
type ListNode struct {
@ -215,7 +214,7 @@ type ListNode struct {
}
```
Scala:
### Scala:
```scala
class ListNode(_x: Int = 0, _next: ListNode = null) {
@ -224,7 +223,7 @@ class ListNode(_x: Int = 0, _next: ListNode = null) {
}
```
Rust:
### Rust:
```rust
#[derive(PartialEq, Eq, Clone, Debug)]
@ -246,3 +245,4 @@ impl<T> ListNode<T> {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -34,6 +34,7 @@
![](https://code-thinking-1253855093.file.myqcloud.com/pics/20211219221812.png)![](https://code-thinking-1253855093.file.myqcloud.com/pics/20211219221812.png)
## 思路
@ -101,7 +102,7 @@ public:
## 其他语言版本
Java
### Java
```Java
public class Solution {
@ -150,8 +151,7 @@ public class Solution {
}
```
Python
### Python
```python
@ -280,7 +280,7 @@ class Solution:
return pointerA
```
Go:
### Go:
```go
func getIntersectionNode(headA, headB *ListNode) *ListNode {
@ -341,7 +341,7 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode {
}
```
JavaScript
### JavaScript
```js
var getListLen = function(head) {
@ -376,7 +376,7 @@ var getIntersectionNode = function(headA, headB) {
};
```
TypeScript
### TypeScript
```typescript
function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): ListNode | null {
@ -413,7 +413,7 @@ function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): Li
};
```
C
### C
```c
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
@ -452,7 +452,7 @@ ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
}
```
Scala:
### Scala:
```scala
object Solution {
@ -508,3 +508,4 @@ object Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>