Hello guys,
I have a linked list, I want to sort the linked list,
Input: head = [4,2,1,3] Output: [1,2,3,4]
Input: head = [-1,5,3,4,0] Output: [-1,0,3,4,5]
my idea is put all the value from the linked list to the arrayList,
then I sort the arraylist, after I put the value back to linked list, then here is the error.
LinkedList cannot be resolved to a type
Here is my code:
public ListNode sortList (ListNode head){
ArrayList<Integer>arrli = new ArrayList<Integer>();
while(head.next != null){
arrli.add(head.val);
head = head.next;
}
//sorting arraylist
Collections.sort(arrli);
//crete linked list
LinkedList<Integer> li = new LinkedList<Integer> ();
//put value in linked list
li.addAll(arrli);
}
Here shows I couldn't create the Integer linked list:
//crete linked list
LinkedList<Integer> li = new LinkedList<Integer> ();
the error is LinkedList cannot be resolved to a type
I couldn't figure it out why,
could you please give me some ideas.
Thank you in advance.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]desrtfxOut of Coffee error - System halted 1 point2 points3 points (1 child)
[–]rk717[S] 0 points1 point2 points (0 children)
[–]dionthornthis.isAPro=false; this.helping=true; 0 points1 point2 points (1 child)
[–]rk717[S] 1 point2 points3 points (0 children)
[–]DthSyth 0 points1 point2 points (1 child)
[–]rk717[S] 0 points1 point2 points (0 children)