using System;
using System.Collections.Generic;
/*
public class ListNode
{
public int val;
public ListNode next;
public ListNode (int x)
{
val = x;
}
}
*/
class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return ListNode类
*/
public ListNode sortLinkedList (ListNode head) {
// write code here
if (head == null)
return null;
List<int> lsN = new List<int>();
ListNode lnR = head;
while (head != null) {
int nVal = head.val;
int nFindIndex = lsN.FindIndex(r => r > nVal);
if (nFindIndex >= 0)
lsN.Insert(nFindIndex, nVal);
else
lsN.Add(nVal);
head = head.next;
}
head = lnR;
int nIndex = 0;
while (head != null) {
head.val = lsN[nIndex];
head = head.next;
nIndex++;
}
return lnR;
}
}