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

  • 相关阅读:
    Dockerfile基于centos镜像编译安装httpd
    Dockerfile基于centos镜像编译安装nginx
    Dockerfile介绍和常用指令
    Docker存储卷
    正则表达式
    Sed与Awk
    Shell函数
    Shell脚本基础
    Autofs
    Podman
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3143100.html
Copyright © 2011-2022 走看看