We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b74463b commit 5f948aaCopy full SHA for 5f948aa
0160-intersection-of-two-linked-lists/0160-intersection-of-two-linked-lists.cpp
@@ -0,0 +1,33 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * struct ListNode {
4
+ * int val;
5
+ * ListNode *next;
6
+ * ListNode(int x) : val(x), next(NULL) {}
7
+ * };
8
+ */
9
+class Solution {
10
+public:
11
+ ListNode* getIntersectionNode(ListNode* headA, ListNode* headB) {
12
+ if (headA == NULL || headB == NULL) {
13
+ return NULL;
14
+ }
15
+ ListNode* temp1 = headA;
16
+ ListNode* temp2 = headB;
17
+
18
+ while (temp1 != temp2) {
19
+ temp1 = temp1->next;
20
+ temp2 = temp2->next;
21
+ if (temp1 == temp2) {
22
+ return temp1;
23
24
+ if (temp1 == NULL) {
25
+ temp1 = headB;
26
27
+ if (temp2 == NULL) {
28
+ temp2 = headA;
29
30
31
32
33
+};
0 commit comments