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

  • 相关阅读:
    冒泡排序
    最长回文子串
    两个排序数组的中位数
    Manacher算法解析
    绕过校园网WEB认证_iodine实现
    绕过校园网WEB认证_dns2tcp实现
    ajax跨域请求
    Vue实例生命周期
    组件化应用构建
    表单输入绑定
  • 原文地址:https://www.cnblogs.com/727713-chuan/p/3306131.html
Copyright © 2011-2022 走看看