YuJian
3 years ago
1 changed files with 24 additions and 0 deletions
@ -1,5 +1,29 @@
@@ -1,5 +1,29 @@
|
||||
## 数组转换成链表 |
||||
|
||||
```typescript |
||||
interface LinkedList { |
||||
value: Number | null; |
||||
next: LinkedList | null; |
||||
} |
||||
|
||||
const toLinkedList = (array: Number[]): LinkedList => { |
||||
let linkedList: LinkedList = { |
||||
value: null, |
||||
next: null, |
||||
}; |
||||
|
||||
const endLength = array.length - 1; |
||||
for (let index = endLength; index >= 0; index--) { |
||||
linkedList = { |
||||
value: array[index], |
||||
next: index === endLength ? null : linkedList, |
||||
}; |
||||
} |
||||
|
||||
return linkedList; |
||||
}; |
||||
``` |
||||
|
||||
## 反转单向链表 |
||||
|
||||
## 使用链表实现队列 |
Loading…
Reference in new issue