avatar
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.valif(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;
}
avatar
c*7
2
没有人知道吗?好像是leetcode的bug
avatar
p*2
3
我刚写了一个,没发现有什么问题。就是leetcode现在很慢。
public ListNode partition(ListNode head, int x) {
ListNode dummy=new ListNode(0);
dummy.next=head;
ListNode newDummy=new ListNode(0);
ListNode p1=dummy;
ListNode p2=newDummy;

while(p1.next!=null){
if(p1.next.valp2.next=p1.next;
p2=p2.next;
p1.next=p1.next.next;
}
else
p1=p1.next;

}

p2.next=dummy.next;
return newDummy.next;
}
avatar
l*8
4
看了一下,是你的程序的bug:
最后几行改成这样,就可以了。
if(small!=null) {
small.next=lh;
if ( large != null)
large.next = null;
} else {
return lh;
}

【在 c****7 的大作中提到】
: 我写了一个,但是它说超时,我没看到有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;

avatar
h*3
5
for the java solution, we have
public class Solution{
public partition(ListNode head, int x){
}
}
Where do you guys define class ListNode? Define in a separate java file or a
member class within Solution ?
thanks
avatar
l*8
6
leetcode online judge上给出了ListNode的定义

a

【在 h******3 的大作中提到】
: for the java solution, we have
: public class Solution{
: public partition(ListNode head, int x){
: }
: }
: Where do you guys define class ListNode? Define in a separate java file or a
: member class within Solution ?
: thanks

avatar
c*7
7
怪不得!!原来是有个loop。怪不得我自己执行不会出错。但是leetcode verify的时
候就死循环了。 高!

【在 l*********8 的大作中提到】
: 看了一下,是你的程序的bug:
: 最后几行改成这样,就可以了。
: if(small!=null) {
: small.next=lh;
: if ( large != null)
: large.next = null;
: } else {
: return lh;
: }

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。