add new solutions
This commit is contained in:
parent
ccb8b5673b
commit
58527849b2
6 changed files with 202 additions and 0 deletions
28
solutions/1/q141/solution.go
Normal file
28
solutions/1/q141/solution.go
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue