Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add typescript solution to locf problem: No.06. 从尾到头打印链表 #424

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add typescript solution to locf problem: No.06. 从尾到头打印链表
  • Loading branch information
zhaocchen committed May 31, 2021
commit d6596724e2c00c782e1738322e9acd63cb45d968
49 changes: 49 additions & 0 deletions lcof/面试题06. 从尾到头打印链表/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ class Solution {
}
```

### **JavaScript**

```js
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {number[]}
*/
var reversePrint = function(head) {
let res = [];
while (head != null) {
res.unshift(head.val);
head = head.next;
}
return res;
};
```

### **Go**

```go
Expand Down Expand Up @@ -179,6 +203,31 @@ public:
};
```

### **TypeScript**

```ts
/**
* Definition for singly-linked list.
* class ListNode {
* val: number
* next: ListNode | null
* constructor(val?: number, next?: ListNode | null) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
* }
*/

function reversePrint(head: ListNode | null): number[] {
let res: number[] = [];
while (head != null) {
res.unshift(head.val);
head = head.next;
}
return res;
};
```

### **...**

```
Expand Down
20 changes: 20 additions & 0 deletions lcof/面试题06. 从尾到头打印链表/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Definition for singly-linked list.
* class ListNode {
* val: number
* next: ListNode | null
* constructor(val?: number, next?: ListNode | null) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
* }
*/

function reversePrint(head: ListNode | null): number[] {
let res: number[] = [];
while (head != null) {
res.unshift(head.val);
head = head.next;
}
return res;
};