博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【LintCode 简单】173. 链表插入排序
阅读量:4088 次
发布时间:2019-05-25

本文共 777 字,大约阅读时间需要 2 分钟。

1.问题描述:

用插入排序对链表排序。

2.样例:

Given 1->3->2->0->null, return 0->1->2->3->null

3.代码:

"""Definition of ListNodeclass ListNode(object):    def __init__(self, val, next=None):        self.val = val        self.next = next"""class Solution:    """    @param: head: The first node of linked list.    @return: The head of linked list.    """    def insertionSortList(self, head):        # write your code here        if head is None:            return None        if head.next is None:            return head        l=ListNode(-9999)        while head:            node=l            fol=head.next            while node.next and node.next.val < head.val:                node = node.next            head.next = node.next            node.next = head            head = fol        return l.next

转载地址:http://wluii.baihongyu.com/

你可能感兴趣的文章
nginx和ftp搭建图片服务器
查看>>
solr5.5基础教程
查看>>
Java中的Zip进行多文件的保存
查看>>
微信扫码支付官方下载的demo本地运行时遇到的坑以及对应解决方法
查看>>
关于js中连续click时不执行访问后台请求,当点击停止2s之后,立即发起访问后台的请求的解决方案
查看>>
RESTClient工具访问服务如何传参
查看>>
MySQL中的分组查询与连接查询语句
查看>>
浮点数精度控制方式总结(含mysql和java)
查看>>
并发限流工具类RateLimiter介绍
查看>>
如何配置Tomcat使用https协议
查看>>
linux下安装mariadb以及相关配置
查看>>
Java中的Gzip进行多文件的保存
查看>>
Java中的Future模式原理自定义实现
查看>>
vmware桥接模式下,配置centos的ip地址网关等,搭建局域网服务器
查看>>
xstream练习
查看>>
调度框架Quartz
查看>>
由单线程到多线程生产消费模式的代码改造历程
查看>>
windows解压缩版mysql5.6.40安装
查看>>
HTTP三次握手实践遇到的问题及对应的解决思路
查看>>
JAVA版基于netty的物联网网关
查看>>