File tree 3 files changed +61
-0
lines changed
3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -89,3 +89,19 @@ public:
89
89
};
90
90
```
91
91
92
+ JS Code:
93
+ ``` javascript
94
+ var oddEvenList = function (head ) {
95
+ if (! head || ! head .next ) return head;
96
+ let odd = head, even = head .next , evenHead = even;
97
+ while (odd .next && even .next ){
98
+ odd .next = even .next ;
99
+ odd = odd .next ;
100
+ even .next = odd .next ;
101
+ even = even .next ;
102
+ }
103
+ odd .next = evenHead;
104
+ return head;
105
+ };
106
+ ```
107
+
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
Original file line number Diff line number Diff line change @@ -93,3 +93,18 @@ public:
93
93
};
94
94
```
95
95
96
+ JS Code:
97
+ ```javascript
98
+ var getKthFromEnd = function(head, k) {
99
+ if(!head) return head;
100
+ let pro = head, after = head;
101
+ for(let i = 0; i < k - 1; i++){
102
+ pro = pro.next;
103
+ }
104
+ while(pro.next){
105
+ pro = pro.next;
106
+ after = after.next;
107
+ }
108
+ return after;
109
+ };
110
+ ```
You can’t perform that action at this time.
0 commit comments