mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2024-11-28 06:48:53 +00:00
剑指offer22 补充js代码
This commit is contained in:
parent
34bfbcb223
commit
cedb32f7b2
@ -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;
|
||||
};
|
||||
```
|
Loading…
Reference in New Issue
Block a user