zoukankan      html  css  js  c++  java
  • 一道面试题

     面试题:

    求字符s1 = "lookyou";和s2 = "likeyou";最长字符交集。输出:“you”
    用一个函数实现;

    C#实现:


            public string Find()
            {
                string s1 = "lookyou";
                string s2 = "likeyou";
                List<string> lst2 = new List<string>();
                int k2 = s2.Length;
                for (int j = 0; j < k2; j++)
                {
                    string tempS = s2.Substring(j);
                    for (int i = 0; i < tempS.Length; i++)
                    {
                        lst2.Add(tempS.Substring(0, i + 1));
                    }
                }

                string tempS1 = "";
                for (int i = 0; i < lst2.Count; i++)
                {
                    string temp2 = lst2[i];
                    if (s1.IndexOf(temp2) > -1)
                    {
                        if (temp2.Length > tempS1.Length)
                        {
                            tempS1 = temp2;
                        }
                    }
                }
                return tempS1;
            }

  • 相关阅读:
    bzoj3293 分金币
    考前模板整理
    CF785D Anton and School
    容斥法解决错排问题
    CF1248F Catowice City
    CF1248E Queue in the Train
    CF1244F Chips
    CF1244C The Football Season
    Noip2016Day1T2 天天爱跑步
    Noip2015Day2T3 运输计划
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3143100.html
Copyright © 2011-2022 走看看