剑指offer22 补充js代码

This commit is contained in:
daluozha 2021-05-05 04:26:39 +08:00
parent 34bfbcb223
commit cedb32f7b2

View File

@ -93,3 +93,18 @@ public:
}; };
``` ```
JS Code:
```javascript
var getKthFromEnd = function(head, k) {
if(!head) return head;
let pro = head, after = head;
for(let i = 0; i < k - 1; i++){
pro = pro.next;
}
while(pro.next){
pro = pro.next;
after = after.next;
}
return after;
};
```