一、题目
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类 the head node
* @return ListNode类
*/
public ListNode sortInList (ListNode head) {
// write code here
if(head == null){
return null;
}
ListNode cur = head;
List<Integer> list = new ArrayList<>();
while(cur != null){
list.add(cur.val);
cur = cur.next;
}
Collections.sort(list);
//int[] arr = list.stream().mapToInt(Integer::valueOf).toArray();
ListNode result = new ListNode(-1);
ListNode node = result;
for(int i = 0;i<list.size();i++){
node.next = new ListNode(list.get(i));
node = node.next;
}
return result.next;
}
}
标签:head,12,ListNode,cur,int,list,必刷,null,TOP101
From: https://blog.51cto.com/u_16244372/8015919