Skip to content

Commit cedb32f

Browse files
committed
剑指offer22 补充js代码
1 parent 34bfbcb commit cedb32f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

animation-simulation/链表篇/剑指offer22倒数第k个节点.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,18 @@ public:
9393
};
9494
```
9595
96+
JS Code:
97+
```javascript
98+
var getKthFromEnd = function(head, k) {
99+
if(!head) return head;
100+
let pro = head, after = head;
101+
for(let i = 0; i < k - 1; i++){
102+
pro = pro.next;
103+
}
104+
while(pro.next){
105+
pro = pro.next;
106+
after = after.next;
107+
}
108+
return after;
109+
};
110+
```

0 commit comments

Comments
 (0)