Skip to content

Commit c3aa567

Browse files
authored
docs: correct inline conditional syntax in intersection-of-two-linked-lists.md
docs: correct inline conditional syntax in getIntersectionNode function Previously, the function attempted to use inline `if` expressions, which are not valid in Go. This change replaces them with proper `if` statements, ensuring correct pointer traversal in finding the intersection node of two linked lists.
1 parent 32faa77 commit c3aa567

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

go/intersection-of-two-linked-lists.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,17 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode {
9292
// Both pointers move through both lists
9393
for a != b {
9494
// When reaching the end of a list, switch to the head of the other list
95-
a = if a == nil { headB } else { a.Next }
96-
b = if b == nil { headA } else { b.Next }
95+
if a == nil {
96+
a = headB
97+
} else {
98+
a = a.Next
99+
}
100+
101+
if b == nil {
102+
b = headA
103+
} else {
104+
b = b.Next
105+
}
97106
}
98107

99108
return a // or b, both are the intersection node or nil if no intersection

0 commit comments

Comments
 (0)