class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
string result;
if( strs.size() == 0 ) {
return result;
}
int len = INT_MAX;
for( int i = 0 ; i < strs.size(); i++ ) {
len = min(len,(int)strs[i].length());
}
for( int col = 0; col < len; col++ ) {
int do_all_match = 1;
for( int i = 0 ; i < strs.size() - 1 ; i++ ) {
if( strs[i][col] == strs[i+1][col] ) {
}
else {
do_all_match = 0;
break;
}
}
if( do_all_match == 1 ) {
result.push_back(strs[0][col]);
}
else {
break;
}
}
return result;
}
};
System Design for Beginners
A masterclass that helps early engineers and product managers become great at designing scalable systems.
132+ learners
Details →System Design Masterclass
A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.
1000+ learners
Details →Redis Internals
Learn internals of Redis by re-implementing some of the core features in Golang.
98+ learners
Details →