add new solutions

This commit is contained in:
kanna5 2025-12-23 17:59:03 +09:00
parent ccb8b5673b
commit 58527849b2
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
6 changed files with 202 additions and 0 deletions

View file

@ -0,0 +1,28 @@
package q141
type ListNode struct {
Val int
Next *ListNode
}
func hasCycle(head *ListNode) bool {
if head == nil {
return false
}
p1, p2 := head, head
for {
for range 2 {
p2 = p2.Next
switch p2 {
case nil:
return false
case p1:
return true
}
}
p1 = p1.Next
}
}
var _ = hasCycle