Movatterモバイル変換


[0]ホーム

URL:


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

Commite4ffe17

Browse files
committed
Add solution #2487
1 parent079a4a0 commite4ffe17

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#1,977 LeetCode solutions in JavaScript
1+
#1,978 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1874,6 +1874,7 @@
18741874
2483|[Minimum Penalty for a Shop](./solutions/2483-minimum-penalty-for-a-shop.js)|Medium|
18751875
2485|[Find the Pivot Integer](./solutions/2485-find-the-pivot-integer.js)|Easy|
18761876
2486|[Append Characters to String to Make Subsequence](./solutions/2486-append-characters-to-string-to-make-subsequence.js)|Medium|
1877+
2487|[Remove Nodes From Linked List](./solutions/2487-remove-nodes-from-linked-list.js)|Medium|
18771878
2490|[Circular Sentence](./solutions/2490-circular-sentence.js)|Easy|
18781879
2493|[Divide Nodes Into the Maximum Number of Groups](./solutions/2493-divide-nodes-into-the-maximum-number-of-groups.js)|Hard|
18791880
2503|[Maximum Number of Points From Grid Queries](./solutions/2503-maximum-number-of-points-from-grid-queries.js)|Hard|
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* 2487. Remove Nodes From Linked List
3+
* https://leetcode.com/problems/remove-nodes-from-linked-list/
4+
* Difficulty: Medium
5+
*
6+
* You are given the head of a linked list.
7+
*
8+
* Remove every node which has a node with a greater value anywhere to the right side of it.
9+
*
10+
* Return the head of the modified linked list.
11+
*/
12+
13+
/**
14+
* Definition for singly-linked list.
15+
* function ListNode(val, next) {
16+
* this.val = (val===undefined ? 0 : val)
17+
* this.next = (next===undefined ? null : next)
18+
* }
19+
*/
20+
/**
21+
*@param {ListNode} head
22+
*@return {ListNode}
23+
*/
24+
varremoveNodes=function(head){
25+
conststack=[];
26+
letcurrent=head;
27+
28+
while(current){
29+
while(stack.length&&stack[stack.length-1].val<current.val){
30+
stack.pop();
31+
}
32+
stack.push(current);
33+
current=current.next;
34+
}
35+
36+
letresult=null;
37+
while(stack.length){
38+
current=stack.pop();
39+
current.next=result;
40+
result=current;
41+
}
42+
43+
returnresult;
44+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp