zoukankan      html  css  js  c++  java
  • Longest Common Prefix

    class Solution {
    public:
        string longestCommonPrefix(vector<string> &strs) {
            // Start typing your C/C++ solution below
            // DO NOT write int main() function
            int size = strs.size();
            if(size == 0)
            return "";
            if(size == 1)
            return strs[0];
            int i = 0;
            string result = "";
            while(1)
            {
                if(strs[0][i] == '')
                break;
                char temp = strs[0][i];
                int j;
                for( j = 1; j < size;j++)
                {
                    if(temp != strs[j][i])
                    break;
                }
                if(j!=size)
                break;
                i++;
                result+=temp;
            }
            return result;
        }
    };

  • 相关阅读:
    C++(四)--线程与进程
    http1.0升级到http1.1
    odoo 基础
    Ubuntu 上安装配置 Ldap
    odoo 怎样使代码生效
    Odoo 创建自定义模块
    开源的软件应用
    域控
    Flask 数据库 SQLAlchemy
    CentOS 8 防火墙 firewall 相关命令
  • 原文地址:https://www.cnblogs.com/727713-chuan/p/3306131.html
Copyright © 2011-2022 走看看