Skip to content

Commit 670edc9

Browse files
add linkedList solution for java
1 parent 7125db6 commit 670edc9

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
|240|[Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/)||Medium|
196196
|239|[Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/)| |Hard|
197197
|238|[Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)| |Medium|
198-
|237|[Node in a Linked List](https://leetcode.com/problems/-node-in-a-linked-list/)| [js](./algorithms/nodeInALinkedList/nodeInALinkedList.js) |Easy|
198+
|237|[Node in a Linked List](https://leetcode.com/problems/-node-in-a-linked-list/)| [js](./algorithms/nodeInALinkedList/nodeInALinkedList.js),[java](./algorithms/nodeInALinkedList/Solution.java) |Easy|
199199
|236|[Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/)| |Medium|
200200
|235|[Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/)| |Easy|
201201
|234|[Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/)| |Easy|
@@ -226,10 +226,10 @@
226226
|209|[Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/)| |Medium|
227227
|208|[Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/)| |Medium|
228228
|207|[Course Schedule](https://leetcode.com/problems/course-schedule/)| |Medium|
229-
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| |Easy|
229+
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [java](./algorithms/reverseLinkedList/Solution.java) |Easy|
230230
|205|[Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/)| |Easy|
231231
|204|[Count Primes](https://leetcode.com/problems/count-primes/)| |Easy|
232-
|203|[Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/)| [js](./algorithms/removeLinkedListElements/removeLinkedListElements.js) |Easy|
232+
|203|[Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/)| [js](./algorithms/removeLinkedListElements/removeLinkedListElements.js),[java](./algorithms/removeLinkedListElements/Solution.java) |Easy|
233233
|202|[Happy Number](https://leetcode.com/problems/happy-number/)| |Easy|
234234
|201|[Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range/)| |Medium|
235235
|200|[Number of Islands](https://leetcode.com/problems/number-of-islands/)| |Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Solution {
2+
public void deleteNode(ListNode node) {
3+
node.val = node.next.val;
4+
node.next = node.next.next;
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Solution {
2+
public ListNode removeElements(ListNode head, int val) {
3+
// 对链表的遍历还需要加强
4+
ListNode sentinel = new ListNode(0);
5+
sentinel.next = head;
6+
7+
ListNode prev = sentinel, curr = head;
8+
while (curr != null) {
9+
if (curr.val == val) prev.next = curr.next;
10+
else prev = curr;
11+
curr = curr.next;
12+
}
13+
return sentinel.next;
14+
}
15+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
public ListNode reverseList(ListNode head) {
3+
ListNode prev = null;
4+
ListNode curr = head;
5+
while (curr != null) {
6+
ListNode nextTemp = curr.next;
7+
curr.next = prev;
8+
prev = curr;
9+
curr = nextTemp;
10+
}
11+
return prev;
12+
}
13+
}

0 commit comments

Comments
 (0)