private void Test()
{
List<int> test = new List<int>() { 1, 5, 3, 6, 2, 8, 10, 11, 12, 15, 18, 13, 17, 16 };
test.Sort();
//key 是StartNum Value 是EndNum
Dictionary<int, int> dicTemp = new Dictionary<int, int>();
// key 是 EndNum Value 是dic 的key
Dictionary<int, int> dic = new Dictionary<int, int>();
int index = -1;
for (int i = 0; i < test.Count; i++)
{
index = test[i] - 1;
if (!dic.ContainsKey(index))
{
dicTemp.Add(test[i], test[i]);
dic.Add(test[i], test[i]);
}
else
{
index = dic[index];
if (dicTemp.ContainsKey(index))
{
dicTemp[index] = test[i];
}
dic.Add(test[i], index);
}
}
Debug.Log(dicTemp);
Debug.Log(dic);
}
其实没啥重要的用,就是简化数据量而已