Skip to content

Commit 52d7e06

Browse files
committed
add js solution for leetcode 83 144 237
1 parent dd4d22e commit 52d7e06

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-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/)| |Easy|
198+
|237|[Node in a Linked List](https://leetcode.com/problems/-node-in-a-linked-list/)| [js](./algorithms/nodeInALinkedList/nodeInALinkedList.js) |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|
@@ -282,7 +282,7 @@
282282
|147|[Insertion Sort List](https://leetcode.com/problems/insertion-sort-list/)| |Medium|
283283
|146|[LRU Cache](https://leetcode.com/problems/lru-cache/)| |Hard|
284284
|145|[Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/)| |Hard|
285-
|144|[Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/)| |Medium|
285+
|144|[Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/)| [js](./algorithms/binaryTreePreorderTraversal/binaryTreePreorderTraversal.js) |Medium|
286286
|143|[Reorder List](https://leetcode.com/problems/reorder-list/)| |Medium|
287287
|142|[Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/)| |Medium|
288288
|141|[Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)| |Medium|
@@ -343,7 +343,7 @@
343343
|86|[Partition List](https://leetcode.com/problems/partition-list/)| |Medium|
344344
|85|[Maximal Rectangle](https://leetcode.com/problems/maximal-rectangle/)| |Hard|
345345
|84|[Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/)| |Hard|
346-
|83|[Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/)| |Easy|
346+
|83|[Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/)| [js](./algorithms/removeDuplicatesFromSortedList/removeDuplicatesFromSortedList.js) |Easy|
347347
|82|[Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/)| |Medium|
348348
|81|[Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii/)| |Medium|
349349
|80|[Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/)| |Medium|

algorithms/binaryTreePreorderTraversal/binaryTreePreorderTraversal.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var deleteNode = function(node) {
2+
// 传入的就是要删除的节点,因此把它用下个节点覆盖即可
3+
node.val = node.next.val;
4+
node.next = node.next.next;
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var deleteDuplicates = function (head) {
2+
let p = head;
3+
while (p && p.next) {
4+
if (p.val === p.next.val) {
5+
p.next = p.next.next;
6+
} else {
7+
p = p.next;
8+
}
9+
}
10+
return head;
11+
};

0 commit comments

Comments
 (0)