码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode953

时间:2018-12-09 20:16:16      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:lse   col   tostring   nop   color   tco   etc   int   derby   

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;
        }
    }

 

leetcode953

标签:lse   col   tostring   nop   color   tco   etc   int   derby   

原文地址:https://www.cnblogs.com/asenyang/p/10092540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!