剑指offer22 补充js代码

pull/22/head
daluozha 2021-05-05 04:26:39 +08:00
parent 34bfbcb223
commit cedb32f7b2
1 changed files with 15 additions and 0 deletions

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;
};
```