The space definitely not constant, but I still got passed .


  • 1
    Y

    class Solution {
    public:
    ListNode *sortList(ListNode *head) {

        std::vector<int> dataVec;
        
        ListNode* pNode = head;
        
        while(pNode)
        {
            dataVec.push_back(pNode->val);
            pNode = pNode->next;
        }
        
        std::sort(dataVec.begin(), dataVec.end());
        
        pNode = head;
        int i = 0;
        while(pNode)
        {
            pNode->val = dataVec[i];
            i++;
            pNode = pNode->next;
        }
        
        return head;
    }
    

    };

    I just tried this for testing purpose only ... Why passed ??


  • 1
    S

    Thanks for your posting. It is true that LeetCode OJ does not check space complexity right now. If people are doubt with their space complexity, here would be the right place to discuss.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.