Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-06-30_14-05-21.png
36.2 KB
#N14. Longest Common Prefix
problem link
#solution
class Solution {
public String longestCommonPrefix(String[] strs) {
String s=strs[0];
int l=s.length(), count=0;
while(l>0){
count=0;
for(String str:strs){
if(str.startsWith(s.substring(0, l))) count++;
}
if(count==strs.length) return s.substring(0, l);
l--;
}
return "";
}
}
👍2