File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,24 @@ public:
79
79
};
80
80
```
81
81
82
+ JS Code:
83
+ ```javascript
84
+ var getIntersectionNode = function(headA, headB) {
85
+ let tempa = headA, tempb = headB
86
+ const map = new Map()
87
+ while(tempa){
88
+ map.set(tempa, 1)
89
+ tempa = tempa.next
90
+ }
91
+ while(tempb){
92
+ if(map.get(tempb))
93
+ return tempb
94
+ tempb = tempb.next
95
+ }
96
+ return tempb
97
+ };
98
+ ```
99
+
82
100
下面这个方法比较巧妙,不是特别容易想到,大家可以自己实现一下,这个方法也是利用我们的双指针思想。
83
101
84
102
下面我们直接看动图吧,特别直观,一下就可以搞懂。
@@ -128,6 +146,18 @@ public:
128
146
};
129
147
```
130
148
149
+ JS Code:
150
+ ```javascript
151
+ var getIntersectionNode = function(headA, headB) {
152
+ let tempa = headA, tempb = headB
153
+ while(tempa !== tempb){
154
+ tempa = tempa ? tempa.next : headB
155
+ tempb = tempb ? tempb.next : headA
156
+ }
157
+ return tempa
158
+ };
159
+ ```
160
+
131
161
好啦,链表的题目就结束啦,希望大家能有所收获,下周就要更新新的题型啦,继续坚持,肯定会有收获的。
132
162
133
163
You can’t perform that action at this time.
0 commit comments