leetcode 关于Partition List# JobHunting - 待字闺中
c*7
1 楼
我写了一个,但是它说超时,我没看到有deadloop啊?而且我放到eclipse里面也没有
问题呀:
怎么回事呢?
Run Status: Time Limit Exceeded
Last executed input
{2,1}, 2
public ListNode partition(ListNode head, int x) {
// Start typing your Java solution below
// DO NOT write main() function
ListNode small=null,large=null;
ListNode sh=null,lh=null;
while(head!=null){
if(head.val if(sh==null){
sh=head;
small=head;
}else{
small.next=head;
small=small.next;
}
}else{
if(lh==null){
lh=head;
large=head;
}else{
large.next=head;
large=large.next;
}
}
head=head.next;
}
if(small!=null)
small.next=lh;
else
return lh;
return sh;
}
问题呀:
怎么回事呢?
Run Status: Time Limit Exceeded
Last executed input
{2,1}, 2
public ListNode partition(ListNode head, int x) {
// Start typing your Java solution below
// DO NOT write main() function
ListNode small=null,large=null;
ListNode sh=null,lh=null;
while(head!=null){
if(head.val
sh=head;
small=head;
}else{
small.next=head;
small=small.next;
}
}else{
if(lh==null){
lh=head;
large=head;
}else{
large.next=head;
large=large.next;
}
}
head=head.next;
}
if(small!=null)
small.next=lh;
else
return lh;
return sh;
}