mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-12 23:36:06 +00:00
1. Add build script for Java.
2. Add height limitation for code blocks in extra.css. 3. Fix "节点" to "结点".
This commit is contained in:
@@ -325,22 +325,9 @@ comments: true
|
||||
=== "Java"
|
||||
|
||||
```java title="linked_list.java"
|
||||
/* 在链表的结点 n0 之后插入结点 P */
|
||||
void insert(ListNode n0, ListNode P) {
|
||||
ListNode n1 = n0.next;
|
||||
n0.next = P;
|
||||
P.next = n1;
|
||||
}
|
||||
|
||||
/* 删除链表的结点 n0 之后的首个结点 */
|
||||
void remove(ListNode n0) {
|
||||
if (n0.next == null)
|
||||
return;
|
||||
// n0 -> P -> n1
|
||||
ListNode P = n0.next;
|
||||
ListNode n1 = P.next;
|
||||
n0.next = n1;
|
||||
}
|
||||
[class]{linked_list}-[func]{insert}
|
||||
|
||||
[class]{linked_list}-[func]{remove}
|
||||
```
|
||||
|
||||
=== "C++"
|
||||
@@ -518,15 +505,7 @@ comments: true
|
||||
=== "Java"
|
||||
|
||||
```java title="linked_list.java"
|
||||
/* 访问链表中索引为 index 的结点 */
|
||||
ListNode access(ListNode head, int index) {
|
||||
for (int i = 0; i < index; i++) {
|
||||
if (head == null)
|
||||
return null;
|
||||
head = head.next;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
[class]{linked_list}-[func]{access}
|
||||
```
|
||||
|
||||
=== "C++"
|
||||
@@ -655,17 +634,7 @@ comments: true
|
||||
=== "Java"
|
||||
|
||||
```java title="linked_list.java"
|
||||
/* 在链表中查找值为 target 的首个结点 */
|
||||
int find(ListNode head, int target) {
|
||||
int index = 0;
|
||||
while (head != null) {
|
||||
if (head.val == target)
|
||||
return index;
|
||||
head = head.next;
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
[class]{linked_list}-[func]{find}
|
||||
```
|
||||
|
||||
=== "C++"
|
||||
|
||||
Reference in New Issue
Block a user