public static int getLength(HeroNode head
){
if (head
.next
== null
){
return 0;
}
int length
= 0;
HeroNode cur
= head
.next
;
while(cur
!=null
){
length
++;
cur
= cur
.next
;
}
return length
;
}
public static HeroNode
fidLastIndexNode(HeroNode head
, int index
){
if (head
.next
== null
){
return null
;
}
int size
= getLength(head
);
if (index
<=0 || index
> size
){
return null
;
}
HeroNode temp
= head
.next
;
for (int i
=0; i
<size
- index
; i
++){
temp
= temp
.next
;
}
return temp
;
}
转载请注明原文地址: https://mac.8miu.com/read-64975.html