public class Solution
    {
        public bool IsAlienSorted(string[] words, string order)
        {
            string HumanDic = "abcdefghijklmnopqrstuvwxyz";
            for (int i = 0; i < words.Length; i++)
            {
                var AlienWord = words[i];
                var HumanWord = "";
                for (int j = 0; 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 = 0; i < words.Length; i++)
            {
                if (words[i] != OrderedWords[i])
                {
                    return false;
                }
            }
            return true;
        }
    }

 

posted on 2018-12-09 19:02  Sempron2800+  阅读(118)  评论(0编辑  收藏  举报