id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,572 | <p>You are given two strings <code>s</code> and <code>t</code> consisting of only lowercase English letters.</p>
<p>Return <em>the minimum number of characters that need to be appended to the end of </em><code>s</code><em> so that </em><code>t</code><em> becomes a <strong>subsequence</strong> of </em><code>s</code>.</... | 0 | {
"code": "class Solution {\npublic:\n int appendCharacters(string s, string t) {\n int sl=s.size(),tl=t.size();\n int j=0;\n for(int i=0;i<sl&&j<tl;i++){\n if(s[i]==t[j]) j++;\n // else break;\n }\n return tl-j;\n }\n};",
"memory": "12200"
} |
2,572 | <p>You are given two strings <code>s</code> and <code>t</code> consisting of only lowercase English letters.</p>
<p>Return <em>the minimum number of characters that need to be appended to the end of </em><code>s</code><em> so that </em><code>t</code><em> becomes a <strong>subsequence</strong> of </em><code>s</code>.</... | 1 | {
"code": "class Solution {\npublic:\n int appendCharacters(string s, string t) {\n int startup = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s[i] == t[startup]) startup++;\n }\n return t.length() - startup;\n }\n};",
"memory": "12300"
} |
2,572 | <p>You are given two strings <code>s</code> and <code>t</code> consisting of only lowercase English letters.</p>
<p>Return <em>the minimum number of characters that need to be appended to the end of </em><code>s</code><em> so that </em><code>t</code><em> becomes a <strong>subsequence</strong> of </em><code>s</code>.</... | 1 | {
"code": "class Solution {\npublic:\n int appendCharacters(string s, string t) {\n int i = 0;\n int j = 0;\n while(i < s.size() && j < t.size())\n {\n if(s[i] == t[j])\n {\n j++;\n }\n i++;\n \n }\n retu... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n static auto _ = []() {\n ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n static auto _ = []() {\n ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\n ListN... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n#include<cstdio>\nclass Sol... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n\nint removeNonMax(ListNode... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n\nint removeNonMax(ListNode... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "class Solution {\npublic:\n ListNode* reverse(ListNode* head){\n ListNode* prev = NULL;\n ListNode* curr = head;\n while(curr){\n ListNode* next = curr->next;\n curr->next = prev;\n prev = curr;\n curr = next;\n }\n return pr... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "class Solution {\npublic:\n ListNode* removeNodes(ListNode* head) {\n ListNode* cur = head;\n vector<int> st;\n\n \n while (cur) {\n \n while (!st.empty() && cur->val > st.back()) {\n st.pop_back(); \n }\n st.push_ba... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "class Solution {\npublic:\n // Helper function to reverse the linked list\n ListNode* reverseList(ListNode* head) {\n ListNode* prev = nullptr;\n ListNode* curr = head;\n while (curr != nullptr) {\n ListNode* next = curr->next;\n curr->next = prev;\n ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\nprivate:\... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\nprivate:\... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "auto speedUP = [](){\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\n\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "class Solution {\npublic:\n ListNode* removeNodes(ListNode* head) {\n stack<ListNode*> st;\n // traverse, push stack, pop until st is empty or \n ListNode* curr = head;\n while (curr != nullptr)\n {\n while (!st.empty() && st.top()->val < curr->val)\n ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 1 | {
"code": "class Solution {\npublic:\n ListNode* removeNodes(ListNode* head) {\n stack<ListNode*> st;\n // traverse, push stack, pop until st is empty or \n ListNode* curr = head;\n while (curr != nullptr)\n {\n while (!st.empty() && st.top()->val < curr->val)\n ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n#include <stack>\nclass Sol... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "class Solution {\npublic:\n ListNode* removeNodes(ListNode* head) {\n \n\n // tc: O(n)\n // sc: (2n)\n\n ListNode* temp = head;\n ListNode* it = head;\n\n stack<int> stk;\n \n\n while( it != NULL )\n {\n stk.push(it->val);\n ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n#pragma GCC optimize(\"O3\"... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\nprivate ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\ninline static auto _ = []()... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "class Solution {\npublic:\n ListNode* removeNodes(ListNode* head) {\n stack<ListNode *> st;\n ListNode *cur = head;\n\n while (cur) {\n st.push(cur);\n cur = cur->next;\n }\n cur = st.top();\n st.pop();\n while (!st.empty()) {\n ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "class Solution {\npublic:\n ListNode* removeNodes(ListNode* head) {\n stack<ListNode *> st;\n ListNode *cur = head;\n\n while (cur) {\n st.push(cur);\n cur = cur->next;\n }\n cur = st.top();\n st.pop();\n while (!st.empty()) {\n ... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\n publi... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\nprivate:\... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\nprivate:\... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n#pragma GCC optimize(\"O3\"... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,573 | <p>You are given the <code>head</code> of a linked list.</p>
<p>Remove every node which has a node with a greater value anywhere to the right side of it.</p>
<p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt=""... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n /*\n1. Store the pointers in vector on purpose for simplicity.\n\n2. Traverse vector from right to left. This will help you identify nodes\n\nto the right larger than ones at the... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.