zoukankan      html  css  js  c++  java
  • leetcode925

    public class Solution
        {
            public bool IsLongPressedName(string name, string typed)
            {
                var list1 = new List<KeyValuePair<char, int>>();
                var list2 = new List<KeyValuePair<char, int>>();
    
                int name_len = name.Length;
                int typed_len = typed.Length;
                if (name_len > typed_len)
                {
                    return false;
                }
                int con = 1;
                var last_char = ' ';
                for (int i = 0; i < name_len - 1; i++)
                {
                    var cur_char = name[i];
                    var next_char = name[i + 1];
                    last_char = next_char;
                    if (cur_char == next_char)
                    {
                        con++;
                    }
                    else
                    {
                        list1.Add(new KeyValuePair<char, int>(cur_char, con));
                        con = 1;
                    }
                }
                list1.Add(new KeyValuePair<char, int>(last_char, con));
    
    
                con = 1;
                last_char = ' ';
                for (int i = 0; i < typed_len - 1; i++)
                {
                    var cur_char = typed[i];
                    var next_char = typed[i + 1];
                    last_char = next_char;
                    if (cur_char == next_char)
                    {
                        con++;
                    }
                    else
                    {
                        list2.Add(new KeyValuePair<char, int>(cur_char, con));
                        con = 1;
                    }
                }
                list2.Add(new KeyValuePair<char, int>(last_char, con));
                if (list1.Count > list2.Count)
                {
                    return false;
                }
                for (int i = 0; i < list1.Count; i++)
                {
                    if (list1[i].Key != list2[i].Key || list1[i].Value > list2[i].Value)
                    {
                        return false;
                    }
                }
                return true;
            }
        }
  • 相关阅读:
    6.12白书第五章图论总结——司雨寒
    【司雨寒】最短路专题总结
    十三 十四周总结
    13周总结--苏康
    JuneX_13
    12总结--苏康
    十二周总结
    每周总结(5.30)——何贤拓
    进阶实验4-3.1 家谱处理 (30分)
    进阶实验2-3.1 海盗分赃 (25分)--递推
  • 原文地址:https://www.cnblogs.com/asenyang/p/9825881.html
Copyright © 2011-2022 走看看