add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent 886b5e0a8e
commit 67cad91898
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
47 changed files with 1549 additions and 1 deletions

View file

@ -0,0 +1,32 @@
package q142
type ListNode struct {
Val int
Next *ListNode
}
func detectCycle(head *ListNode) *ListNode {
p1, p2 := head, head
for p1 != nil && p2 != nil {
p1 = p1.Next
p2 = p2.Next
if p2 != nil {
p2 = p2.Next
}
if p1 == p2 {
break
}
}
if p2 == nil {
return nil
}
p1 = head
for p1 != p2 {
p1 = p1.Next
p2 = p2.Next.Next
}
return p1
}
var _ = detectCycle