class Solution {
public ListNode reverseList(ListNode head) {
ListNode tmp=null;
if (head.next != null) {
tmp = reverseList(head.next);
head.next = head;
}else{
tmp = head;
}
return tmp;
}
public static void main ( String[] args) {
String input = "1->2->3->4->5->NULL";
String word="";
int wordIdx=-1;
ListNode head = null;
ListNode current = head;
int len = input.length();
for (int i =0; i< len-6; i++ ) {
if ((input.charAt(i)== '-') && (input.charAt(i+1)== '>')) {
if ((input.charAt(i+2)=='L') && ( input.charAt(i+3)=='L')){
i=len;
}
else {
if (head == null) {
head = new ListNode( Integer.parseInt(word));
}else {
current.next = new ListNode( Integer.parseInt(word));
current = current.next;
}
wordIdx=0;
i++;
}
} else {
word.concat(input.substring(i,i));
}
}//for
Solution solve = new Solution();
head = solve.reverseList(head);
//print list
while ( head != null ){
System.out.print(head.val);
if ( head.next == null )
System.out.println("->NULL");
else
System.out.println("->");
head = head.next;
}
}//main
}
class ListNode{
int val;
ListNode next;
ListNode(int x) { val = x; }
}
I am getting Run time error :
... noSuchMethod ...
Not sure about the reasons. Are the library versions consist ? Do I have 2 threads running ?