题解 | #输出单向链表中倒数第k个结点#
输出单向链表中倒数第k个结点
https://www.nowcoder.com/practice/54404a78aec1435a81150f15f899417d
package main import "fmt" type ListNode1 struct { m_nKay int m_pNext *ListNode1 } func main() { for { var n int _,err := fmt.Scan(&n) if err != nil { break } head := new(ListNode1) M := head for i := 0; i < n; i++ { node := new(ListNode1) fmt.Scan(&node.m_nKay) M.m_pNext = node M = node } var k int fmt.Scan(&k) j := 1 K := head for P := head; P.m_pNext != nil; P = P.m_pNext { if j < k { j++ continue } else { K = K.m_pNext } } fmt.Println(K.m_nKay) } }