We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 46ee88e commit bfe84dbCopy full SHA for bfe84db
Partition_List.cc
@@ -35,4 +35,29 @@ class Solution {
35
}
36
return head;
37
38
-};
+};
39
+
40
+//Another method using second level pointer
41
+class Solution {
42
+public:
43
+ ListNode *partition(ListNode *head, int x) {
44
+ // Start typing your C/C++ solution below
45
+ // DO NOT write int main() function
46
+ ListNode *ret = NULL;
47
+ ListNode **tail = &ret;
48
+ ListNode **pHead = &head;
49
+ ListNode *entry = NULL;
50
+ for (ListNode **pCur = &head; *pCur; ) {
51
+ entry = *pCur;
52
+ if (entry->val < x) {
53
+ *pCur = entry->next;
54
+ *tail = entry;
55
+ tail = &(entry->next);
56
+ } else {
57
+ pCur = &(entry->next);
58
+ }
59
60
+ *tail = *pHead;
61
+ return ret;
62
63
0 commit comments