Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cdee514

Browse files
committed
feat: add module 'High frequency interview questions'
添加面试高频题模块
1 parent 2d06934 commit cdee514

File tree

9 files changed

+273
-36
lines changed

9 files changed

+273
-36
lines changed

‎README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@
3131
- [LeetCode 《剑指 Offer(第 2 版)》](/lcof/README.md)
3232
- [LeetCode 《程序员面试金典(第 6 版)》](/lcci/README.md)
3333

34+
## 面试高频题
35+
36+
### 数组
37+
38+
### 链表
39+
40+
1. [从尾到头打印链表](./lcof/面试题06.%20从尾到头打印链表/README.md)
41+
1. [删除链表的节点](./lcof/面试题18.%20删除链表的节点/README.md)
42+
1. [链表中倒数第 k 个节点](./lcof/面试题22.%20链表中倒数第k个节点/README.md)
43+
1. [反转链表](./solution/0200-0299/0206.Reverse%20Linked%20List/README.md)
44+
1. [环形链表](./solution/0100-0199/0141.Linked%20List%20Cycle/README.md)
45+
1. [环形链表 II](./solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md)
46+
47+
### 二叉树
48+
49+
### 数学
50+
51+
### 栈和队列
52+
53+
### 动态规划
54+
55+
### 混合问题
56+
3457
## 维护者
3558

3659
[Yang Libin](https://github.com/yanglbme): GitHub 技术社区 [@Doocs](https://github.com/doocs) 创建者;[@TheAlgorithms](https://github.com/TheAlgorithms) 组织成员。

‎README_EN.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF
3131
- [LCOF: *Coding Interviews, 2nd Edition*](/lcof/README_EN.md)
3232
- [LCCI: *Cracking the Coding Interview, 6th Edition*](/lcci/README_EN.md)
3333

34+
## High frequency interview questions
35+
36+
### Arrays
37+
38+
### Linked List
39+
40+
1.
41+
42+
### Binary Tree
43+
44+
### Math
45+
46+
### Stack & Queue
47+
48+
### Dynamic Programming
49+
50+
### Misc
51+
52+
3453
## Maintainer
3554

3655
[Yang Libin](https://github.com/yanglbme): Creator of [@Doocs](https://github.com/doocs) technical community; member of [@TheAlgorithms](https://github.com/TheAlgorithms) organization.

‎lcof/面试题24. 反转链表/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var reverseList = function(head) {
9696

9797
### **Go**
9898

99-
```Go
99+
```go
100100
func reverseList(head *ListNode) *ListNode {
101101
if head == nil ||head.Next == nil {
102102
return head

‎solution/0200-0299/0206.Reverse Linked List/README.md‎

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,109 @@
1717

1818

1919
## 解法
20-
<!-- 这里可写通用的实现逻辑 -->
20+
21+
定义指针 `p``q` 分别指向头节点和下一个节点,`pre` 指向头节点的前一个节点。
22+
23+
遍历链表,改变指针 `p` 指向的节点的指向,将其指向 `pre` 指针指向的节点,即 `p.next = pre`。然后 `pre` 指针指向 `p`,`p``q` 指针往前走。
24+
25+
当遍历结束后,返回 `pre` 指针即可。
2126

2227

2328
<!-- tabs:start -->
2429

2530
### **Python3**
26-
<!-- 这里可写当前语言的特殊实现逻辑 -->
27-
2831
```python
29-
32+
# Definition for singly-linked list.
33+
# class ListNode:
34+
# def __init__(self, x):
35+
# self.val = x
36+
# self.next = None
37+
38+
class Solution:
39+
def reverseList(self, head: ListNode) -> ListNode:
40+
pre, p = None, head
41+
while p:
42+
q = p.next
43+
p.next = pre
44+
pre = p
45+
p = q
46+
return pre
3047
```
3148

3249
### **Java**
33-
<!-- 这里可写当前语言的特殊实现逻辑 -->
34-
3550
```java
51+
/**
52+
* Definition for singly-linked list.
53+
* public class ListNode {
54+
* int val;
55+
* ListNode next;
56+
* ListNode(int x) { val = x; }
57+
* }
58+
*/
59+
class Solution {
60+
public ListNode reverseList(ListNode head) {
61+
ListNode pre = null;
62+
ListNode p = head;
63+
while (p != null) {
64+
ListNode q = p.next;
65+
p.next = pre;
66+
pre = p;
67+
p = q;
68+
}
69+
return pre;
70+
}
71+
}
72+
```
73+
74+
### **JavaScript**
75+
```js
76+
/**
77+
* Definition for singly-linked list.
78+
* function ListNode(val) {
79+
* this.val = val;
80+
* this.next = null;
81+
* }
82+
*/
83+
/**
84+
* @param {ListNode} head
85+
* @return {ListNode}
86+
*/
87+
var reverseList = function(head) {
88+
let node = head
89+
let pre = null
90+
while(node) {
91+
let cur = node
92+
node = cur.next
93+
cur.next = pre
94+
pre = cur
95+
}
96+
return pre
97+
};
98+
```
3699

100+
### **Go**
101+
102+
```Go
103+
func reverseList(head *ListNode) *ListNode {
104+
if head == nil ||head.Next == nil {
105+
return head
106+
}
107+
dummyHead := &ListNode{}
108+
cur := head
109+
for cur != nil {
110+
tmp := cur.Next
111+
cur.Next = dummyHead.Next
112+
dummyHead.Next = cur
113+
cur = tmp
114+
}
115+
return dummyHead.Next
116+
}
37117
```
38118

119+
120+
39121
### **...**
122+
40123
```
41124
42125
```

‎solution/0200-0299/0206.Reverse Linked List/README_EN.md‎

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,98 @@
3636
<!-- tabs:start -->
3737

3838
### **Python3**
39-
4039
```python
41-
40+
# Definition for singly-linked list.
41+
# class ListNode:
42+
# def __init__(self, x):
43+
# self.val = x
44+
# self.next = None
45+
46+
class Solution:
47+
def reverseList(self, head: ListNode) -> ListNode:
48+
pre, p = None, head
49+
while p:
50+
q = p.next
51+
p.next = pre
52+
pre = p
53+
p = q
54+
return pre
4255
```
4356

4457
### **Java**
45-
4658
```java
59+
/**
60+
* Definition for singly-linked list.
61+
* public class ListNode {
62+
* int val;
63+
* ListNode next;
64+
* ListNode(int x) { val = x; }
65+
* }
66+
*/
67+
class Solution {
68+
public ListNode reverseList(ListNode head) {
69+
ListNode pre = null;
70+
ListNode p = head;
71+
while (p != null) {
72+
ListNode q = p.next;
73+
p.next = pre;
74+
pre = p;
75+
p = q;
76+
}
77+
return pre;
78+
}
79+
}
80+
```
4781

82+
### **JavaScript**
83+
```js
84+
/**
85+
* Definition for singly-linked list.
86+
* function ListNode(val) {
87+
* this.val = val;
88+
* this.next = null;
89+
* }
90+
*/
91+
/**
92+
* @param {ListNode} head
93+
* @return {ListNode}
94+
*/
95+
var reverseList = function(head) {
96+
let node = head
97+
let pre = null
98+
while(node) {
99+
let cur = node
100+
node = cur.next
101+
cur.next = pre
102+
pre = cur
103+
}
104+
return pre
105+
};
48106
```
49107

108+
### **Go**
109+
110+
```Go
111+
func reverseList(head *ListNode) *ListNode {
112+
if head == nil ||head.Next == nil {
113+
return head
114+
}
115+
dummyHead := &ListNode{}
116+
cur := head
117+
for cur != nil {
118+
tmp := cur.Next
119+
cur.Next = dummyHead.Next
120+
dummyHead.Next = cur
121+
cur = tmp
122+
}
123+
return dummyHead.Next
124+
}
125+
```
126+
127+
128+
50129
### **...**
130+
51131
```
52132
53133
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func reverseList(head *ListNode) *ListNode {
2+
if head == nil ||head.Next == nil {
3+
return head
4+
}
5+
dummyHead := &ListNode{}
6+
cur := head
7+
for cur != nil {
8+
tmp := cur.Next
9+
cur.Next = dummyHead.Next
10+
dummyHead.Next = cur
11+
cur = tmp
12+
}
13+
return dummyHead.Next
14+
}

‎solution/0200-0299/0206.Reverse Linked List/Solution.java‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@
88
*/
99
class Solution {
1010
public ListNode reverseList(ListNode head) {
11-
if (head == null) return null;
12-
ListNode reverse = null;
13-
while (head != null) {
14-
ListNode temp = head;
15-
head = head.next;
16-
if (reverse == null) {
17-
reverse = temp;
18-
temp.next = null;
19-
} else {
20-
temp.next = reverse;
21-
reverse = temp;
22-
}
11+
ListNode pre = null;
12+
ListNode p = head;
13+
while (p != null) {
14+
ListNode q = p.next;
15+
p.next = pre;
16+
pre = p;
17+
p = q;
2318
}
24-
return reverse;
19+
return pre;
2520
}
2621
}
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
const reverseList = function(head){
2-
if(head == null){
3-
return head;
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val) {
4+
* this.val = val;
5+
* this.next = null;
6+
* }
7+
*/
8+
/**
9+
* @param {ListNode} head
10+
* @return {ListNode}
11+
*/
12+
var reverseList = function(head) {
13+
let node = head
14+
let pre = null
15+
while(node) {
16+
let cur = node
17+
node = cur.next
18+
cur.next = pre
19+
pre = cur
420
}
5-
let cur = head;
6-
let pre = null, tmp = null;
7-
while(cur != null){
8-
tmp = cur.next;
9-
cur.next = pre;
10-
pre = cur;
11-
cur = tmp;
12-
}
13-
return pre;
14-
}
21+
return pre
22+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution:
8+
def reverseList(self, head: ListNode) -> ListNode:
9+
pre, p = None, head
10+
while p:
11+
q = p.next
12+
p.next = pre
13+
pre = p
14+
p = q
15+
return pre

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /