leetcode953

时间:2020-12-05 05:20:03
public class Solution
{
public bool IsAlienSorted(string[] words, string order)
{
string HumanDic = "abcdefghijklmnopqrstuvwxyz";
for (int i = ; i < words.Length; i++)
{
var AlienWord = words[i];
var HumanWord = "";
for (int j = ; j < AlienWord.Length; j++)
{
var ch = AlienWord[j];
var position = order.IndexOf(ch);
var realch = HumanDic[position];
HumanWord += realch.ToString();
}
words[i] = HumanWord;
} var OrderedWords = words.OrderBy(x => x).ToArray();
for (int i = ; i < words.Length; i++)
{
if (words[i] != OrderedWords[i])
{
return false;
}
}
return true;
}
}

相关文章