avatar
a*0
1
不递归无非就是分成两半 后一办reverse 然后插入到第一份去 我懒得写这么多代码
于是用了递归方法 结果超时 在自己电脑上跑了几个小case 都过了 不知道大家什么看
法 又超时了!
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {

public void reorderList(ListNode head) {

if(head == null)
return;

if(head.next ==null)
return;

if(head.next.next == null)
return;



ListNode scanner = head;
int length =0;
while(scanner != null){
length++;
scanner = scanner.next;
}

head = reorderHelper(head, length);


}


public ListNode reorderHelper(ListNode start, int range){

ListNode scanner =start;
ListNode last = start;
int count = range-2;

if(range ==0)
return null;

if(range ==1)
return start;


while(count >0){
count--;
scanner = scanner.next;
}

last = scanner.next;
scanner.next = null;

ListNode temp = reorderHelper(start.next, range -2);

start.next = last;
last.next = temp;


return start;
}

}
avatar
m*w
2
【 以下文字转载自 shopping 讨论区 】
发信人: microwindow (microsoft), 信区: shopping
标 题: 问一下att手机plan
发信站: BBS 未名空间站 (Thu Dec 23 17:36:32 2010, 美东)
问题比较多,先在这个版上问问。
att以前的5条线要到期了。到期后只想要两条线。如果开个新plan可以保留原来的两个
号码吗?保留号码是不是只能在原来的计划上upgrade,还必须要5条线?如果在原来的
账户上只要2条线,删掉3条线,还能换新的手机吗?谢谢。
avatar
O*O
3
请问有人知道为啥我在USCIS网站上查 I485 的 case status,总是被告知系统不认识我
case number吗? 过去几周我试了好几次了都不行,我输的case number 肯定没错。有
人有同样的经历吗?多谢!
avatar
p*e
4
我的没超时,供你参考。
// return the tail of the list (index = end+1)
ListNode* reorderHelper(ListNode* head, int start, int end){
if (start > end){
return NULL;
}
if (start == end) {
ListNode* tail = head->next;
head->next = NULL;
return tail;
}
else if (end == start + 1){
ListNode* tail = head->next->next;
head->next->next = NULL;
return tail;
}

ListNode* tail = reorderHelper(head->next, start+1, end-1);
ListNode* rt = tail->next;
tail->next = head->next;
head->next = tail;
return rt;
}

void reorderList(ListNode *head) {
if (!head) return;

int count = 0;
ListNode* n = head;
while(n){
count ++;
n = n->next;
}

reorderHelper(head, 0, count-1);
}
avatar
z*q
5
如果在原来的
yes
avatar
d*s
6
你收到receipt没有?用上面的number,没听说有错的
avatar
a*0
7
雪中送炭啊

【在 p*****e 的大作中提到】
: 我的没超时,供你参考。
: // return the tail of the list (index = end+1)
: ListNode* reorderHelper(ListNode* head, int start, int end){
: if (start > end){
: return NULL;
: }
: if (start == end) {
: ListNode* tail = head->next;
: head->next = NULL;
: return tail;

avatar
G*8
8
att以前的5条线要到期了。到期后只想要两条线。如果开个新plan可以保留原来的两个
号码吗?
Yes
保留号码是不是只能在原来的计划上upgrade,还必须要5条线?
不用upgrade。只想要上1条线都可以。
如果在原来的账户上只要2条线,删掉3条线,还能换新的手机吗?谢谢
可以
avatar
O*O
9
收到receipt了,就是用那上面的number, 问过律师,她让我多试试. 并且我已经打过指
摸了. 我很奇怪,不知问题出在哪里?
avatar
p*e
10
那就发个包子给我呗,我如今是赤贫啊,想求个bless都没包子发 T_T
avatar
l*u
11
Same here. the website cannot recognize the receipt number. Same thing had
happened to my I765 and I131 receipt number until the both case were
approved.
avatar
a*0
12
没看懂

【在 p*****e 的大作中提到】
: 我的没超时,供你参考。
: // return the tail of the list (index = end+1)
: ListNode* reorderHelper(ListNode* head, int start, int end){
: if (start > end){
: return NULL;
: }
: if (start == end) {
: ListNode* tail = head->next;
: head->next = NULL;
: return tail;

avatar
y*z
13
我去年4月交的 ,所有的receipt 网上都查不到,ead, ap, 485,
ead 和ap 还是 approve了过海才查的到的,
现在485 还是查不到, 每次要了解信息都要打电话到2 tier manager 去问, 她每次
都说,系统技术问题放不上来, 已经无语了,
avatar
a*0
14
原因找到了 递归method之中有一个线性的操作 这样会导致整体的n平方复杂度
avatar
z*n
15
USCIS网站的数据可能不准确,半年多前就Approved的case在它上面还是Case received
avatar
p*e
16
其实和你的方法差不多啊,你用一个length,我用一个start index和end index。
比如:
0 -> 1 -> 2 -> 3 -> 4 -> 5,
helper(start=0, end=5) calls helper(start=1, end=4). helper(start=1, end=4)
把 1->2->3->4 reverse成 4->3->2->1,还返回5,那么helper(start=0, end=5)就把
header(0)和返回的那个5link起来,再link helper(start=1, end=4)的header就行
了。

【在 a**********0 的大作中提到】
: 没看懂
avatar
k*g
17
My h1b amendment has the same problem. Already got the receipt, but the
USCIS website told the same error message.
Does anyone know the reason?
avatar
a*0
18
你的递归中没有O(n)的操作 我的有 所以用 length不好 应该直接给出最后一个节点
的指针

【在 p*****e 的大作中提到】
: 其实和你的方法差不多啊,你用一个length,我用一个start index和end index。
: 比如:
: 0 -> 1 -> 2 -> 3 -> 4 -> 5,
: helper(start=0, end=5) calls helper(start=1, end=4). helper(start=1, end=4)
: 把 1->2->3->4 reverse成 4->3->2->1,还返回5,那么helper(start=0, end=5)就把
: header(0)和返回的那个5link起来,再link helper(start=1, end=4)的header就行
: 了。

avatar
a*0
19
我觉得有个很难理解的
return的是本次调整之后链表的最后一个的下一个节点 并且此节点和前边部分不再链接

【在 p*****e 的大作中提到】
: 其实和你的方法差不多啊,你用一个length,我用一个start index和end index。
: 比如:
: 0 -> 1 -> 2 -> 3 -> 4 -> 5,
: helper(start=0, end=5) calls helper(start=1, end=4). helper(start=1, end=4)
: 把 1->2->3->4 reverse成 4->3->2->1,还返回5,那么helper(start=0, end=5)就把
: header(0)和返回的那个5link起来,再link helper(start=1, end=4)的header就行
: 了。

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