码迷,mamicode.com
首页 > 其他好文 > 详细

Partition List

时间:2014-10-10 19:36:04      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   for   sp   div   art   

 

# Definition for singly-linked list.
class ListNode:
     def __init__(self, x):
         self.val = x
         self.next = None

class Solution:
    # @param head, a ListNode
    # @param x, an integer
    # @return a ListNode
    def partition(self, head, x):
        if head==None:
            return head
less_node_list=ListNode(0) greater_node_list=ListNode(0) head1=less_node_list head2=greater_node_list
while head!=None: if head.val<x: head1.next=ListNode(head.val) head1=head1.next else: head2.next=ListNode(head.val) head2=head2.next head=head.next
head1.next
=greater_node_list.next return less_node_list.next

 

Partition List

标签:style   blog   color   io   ar   for   sp   div   art   

原文地址:http://www.cnblogs.com/iois/p/4016474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!