public class Solution { public char NextGreatestLetter(char[] letters, char target) { //a-97 z-122 var dic = new List>(); //key存储当前值,int是下一个值 for (int i = 0; i < letters.Length - 1; i++) { dic.Add(new KeyValuePair (letters[i], letters[i + 1])); } dic.Add(new KeyValuePair (letters[letters.Length - 1], ' ')); if (target < dic[0].Key || target >= dic[dic.Count - 1].Key) { return dic[0].Key; } for (int i = 0; i < dic.Count; i++) { if (target >= dic[i].Key && target < dic[i].Value) { return dic[i].Value; } } return dic[0].Key; } }