mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-16 19:01:45 +00:00
添加Go语言题解
This commit is contained in:
@@ -163,3 +163,23 @@ class Solution {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Go Code:
|
||||
|
||||
```go
|
||||
func getKthFromEnd(head *ListNode, k int) *ListNode {
|
||||
if head == nil { return head }
|
||||
pro, after := head, head
|
||||
//先移动绿指针到指定位置
|
||||
for i := 0; i < k - 1; i++ {
|
||||
pro = pro.Next
|
||||
}
|
||||
for pro.Next != nil {
|
||||
pro = pro.Next
|
||||
after = after.Next
|
||||
}
|
||||
return after
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user