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;
            }
        }
  • 相关阅读:
    Python使用inspect查看代码参数
    Python的hasattr() getattr() setattr()
    Module-GitBook使用手册
    Module-Hadoop技术文档
    Module-Git使用手册
    Module-Faker使用手册
    Module-Docker使用手册
    Module-DB2技术文档
    Module-Dask并行任务调度
    Module-Apache使用说明
  • 原文地址:https://www.cnblogs.com/asenyang/p/9825881.html
Copyright © 2011-2022 走看看