链表- leetcode 147. Insertion Sort List
来源:互联网 发布:类似acdsee的软件 编辑:程序博客网 时间:2024/05/16 14:23
原题链接:Insertion Sort List
题解:
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* insertionSortList(ListNode* head) { /* Time Complexity:O(N) Space Complexity:O(1) */ if(!head || !head->next)return head; ListNode *start=head,*tmp=head,*after=NULL; head=head->next; start->next=NULL; while(head){ after=head->next; while(tmp->next){ if(tmp->val<head->val && tmp->next->val<head->val)tmp=tmp->next; else break; } if(tmp->val>head->val){ head->next=tmp; start=head; } else{ head->next=tmp->next; tmp->next=head; } tmp=start; head=after; } return start; }};
阅读全文
0 0
- 链表- leetcode 147. Insertion Sort List
- LeetCode 147. Insertion Sort List
- [LeetCode]147.Insertion Sort List
- [leetcode] 147.Insertion Sort List
- 147. Insertion Sort List LeetCode
- LeetCode 147. Insertion Sort List
- LeetCode *** 147. Insertion Sort List
- Leetcode 147. Insertion Sort List
- leetcode.147. Insertion Sort List
- leetcode 147. Insertion Sort List
- LeetCode-147.Insertion Sort List
- LeetCode - 147. Insertion Sort List
- [leetcode] 147. Insertion Sort List
- [LeetCode] 147. Insertion Sort List
- Leetcode-147. Insertion Sort List
- [LeetCode]147. Insertion Sort List
- LeetCode 147. Insertion Sort List
- 【LeetCode】 147. Insertion Sort List
- SourceInsight 4破解
- 一分钟了解“MAC OS 和 Windows系统的优劣对比”
- 小程序-网络请求框架封装
- Android_设备隐私获取,忽略6.0权限管理
- 分布式锁 Java常用技术方案
- 链表- leetcode 147. Insertion Sort List
- java单选框复选框案例练习
- 为什么session.commit引起事务的提交,session.insert和delete底层到底是什么
- PHP中常见的设计模式
- 图片无缝向左滚动
- Github生成公钥私钥的方法
- 为PHP7.0安装redis扩展
- Swift4学习笔记6——函数(Function)
- CentOS上安装JDK