# I have a non-recursive solution but I want to further reduce the run time? Any idea?

• ``````class Solution {
public:

int listLen = 0;
for (ListNode *pos = head; pos; pos = pos->next)
++listLen;

for (int partLen = 1; partLen <= listLen; partLen += partLen) {
ListNode *prevNewEnd{};

while (pos != nullptr) {
auto left = pos;
auto leftEnd = move(left, partLen);
auto right = leftEnd;
auto rightEnd = move(right, partLen);
pos = rightEnd;
ListNode *newEnd{};
auto p = merge(left, leftEnd, right, rightEnd, &newEnd);

if (prevNewEnd)
prevNewEnd->next = p;

prevNewEnd = newEnd;

}
}

}

ListNode *leftEnd,
ListNode *rightEnd,
ListNode **newEnd) {

while (left != leftEnd || right != rightEnd) {
if (left != leftEnd && right != rightEnd) {
if(left->val <= right->val) {
writer->next = left;
left = left->next;
} else {
writer->next = right;
right = right->next;
}
} else if (left != leftEnd) {
writer->next = left;
left = left->next;
} else if (right != rightEnd) {
writer->next = right;
right = right->next;
} else
break;

writer = writer->next;

}

writer->next = rightEnd;
*newEnd = writer;