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;
            }
        }
  • 相关阅读:
    SqlHelper
    C#中gridView常用属性和技巧介绍
    oracle中的存储过程例子
    log4j.properties配置详解
    Ant之build.xml
    jQuery源码
    jQuery实现分页
    mysql中log
    SQL只获取字段中的中文字符
    子Repeater获取父级Repeater绑定项的值
  • 原文地址:https://www.cnblogs.com/asenyang/p/9825881.html
Copyright © 2011-2022 走看看