【LeetCode字符串】--14.最长公共前缀

14.最长公共前缀

java 复制代码
class Solution {
    public String longestCommonPrefix(String[] strs) {
        if(strs == null || strs.length == 0){
            return "";
        }
        int length = strs[0].length();
        int count = strs.length;
        for(int i =0;i<length;i++){
            char c = strs[0].charAt(i);
            for(int j = 1;j<count;j++){
                if(i == strs[j].length() || strs[j].charAt(i) != c){
                    return strs[0].substring(0,i);
                }
            }
        }
        return strs[0];

    }
}
相关推荐
shehuiyuelaiyuehao1 分钟前
算法54,链表 两数相加
数据结构·算法·链表
147API26 分钟前
如何设计“回答、追问、停答”三类蒸馏训练集
人工智能·算法·机器学习
朝朝辞暮i41 分钟前
C++ 第7课 while 循环
开发语言·c++·算法
blxr_1 小时前
力扣hot100爬楼梯https://leetcode.cn/problems/climbing-stairs/
算法·leetcode·职场和发展
pride.li1 小时前
ISP标定-NR标定(Noise Reduction,降噪校准)
算法·计算机视觉·isp
CQU_JIAKE2 小时前
9.29【A】
算法·深度优先
没落之王2 小时前
AI在文言文——论文脉复苏对AI的意义
大数据·人工智能·算法
u0111026752 小时前
工具页案例图如何编写 alt让图片说明与处理场景对应
java·前端·javascript·图像处理·人工智能·算法·ai作画
阿狗童鞋3 小时前
数据结构与算法实战指南
数据结构·算法
Navigator_Z3 小时前
LeetCode //C - 1275. Find Winner on a Tic Tac Toe Game
c语言·算法·leetcode