Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions 3043. Find the Length of the Longest Common Prefix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public:
int longestCommonPrefix(vector<int>& arr1, vector<int>& arr2) {
set<int> st;
for (auto num : arr1) {
while (num > 0) {
st.insert(num);
num /= 10;
}
}
int maxi = 0;
for (auto num : arr2) {
int temp = num;
while (temp > 0) {

if (st.find(temp) != st.end()) {
int len = (int)log10(temp) + 1;
maxi = max(maxi, len);
break;
}
temp /= 10;
}
}
return maxi;
}
};
Loading