只是简单的交换值,这题目还算简单的,最暴力的就是直接建立一个新链,比较塞入:
public class Solution {
/**
*
* @param head ListNode类 the head node
* @return ListNode类
*/
public ListNode sortInList (ListNode head) {
ListNode result = head;
while(head != null){
ListNode root = head;
ListNode checkStart = head.next;
while(checkStart != null){
if(checkStart.val < root.val){
int temp = root.val;
root.val = checkStart.val;
checkStart.val = temp;
}
checkStart = checkStart.next;
}
head = head.next;
}
return result;
}
}