mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2024-11-24 13:03:41 +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