C++ 最实用最快速的方法

/**
*  struct ListNode {
*        int val;
*        struct ListNode *next;
*        ListNode(int x) :
*              val(x), next(NULL) {
*        }
*  };
*/
class Solution {
public:
    vector<int> printListFromTailToHead(ListNode* head) {
        vector<int> res;
        while(head){
            res.insert(res.begin(),head->val);
            head = head->next;
        }
        return res;
    }
    
};
暴力解决,简单实用。
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务