mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-01 21:41:36 +00:00
剑指offer22 补充js代码
This commit is contained in:
@@ -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;
|
||||
};
|
||||
```
|
Reference in New Issue
Block a user