leetcode之insertion-sort-list
来源:互联网 发布:iphone优酷连不上网络 编辑:程序博客网 时间:2024/05/10 04:03
题目描述
Sort a linked list using insertion sort.
思路:新建一个链表,遍历原链表,将每个节点加入新链表正确的位置。
class Solution {public: ListNode *insertionSortList(ListNode *head) { if(!head || !head ->next) { return head; } list<int> v; for(ListNode *p = head; p!=NULL; p = p->next) { v.push_back(p->val); //把链表的元素存储到线性表 } v.sort(); //直接调用sort进行排序 for(ListNode *p = head; p != NULL; p = p->next) { p ->val = v.front(); //把线性表排好序的序列一个个赋值给链表 v.pop_front(); } return head; }};
0 0
- leetcode之Insertion Sort List
- leetcode之Insertion Sort List
- leetcode之Insertion Sort List
- leetcode之Insertion Sort List
- LeetCode之Insertion Sort List
- leetcode之insertion Sort list
- leetcode之insertion-sort-list
- leetcode之insertion-sort-list
- leetCode解题报告之Insertion Sort List
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Leetcode: Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- python CGI环境搭建
- Centos 7.0 execute yum update ——File "/usr/libexec/urlgrabber-ext-down", line 75, in <module>
- 如何在QT中给程序添加图标
- Median of Two Sorted Arrays (第二周:分治法)
- sql开发笔记
- leetcode之insertion-sort-list
- String与StringBuilder区别
- 伪类、伪元素的区别
- 退役感言
- CDOJ 1330 柱爷与远古法阵 概率DP,高斯消元,卡精度,极度恶心
- Jenkins 入门系列--jenkins 介绍
- 判断网络
- java复习 return,break,continue关键字
- 处理iphone手机不能自动播放音频问题