leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

3043.cpp (574B)


0 class Solution {
1 public:
2 int longestCommonPrefix(const vector<int> &arr1, const vector<int> &arr2) const {
3 unordered_set<int> us;
4 int res = 0;
6 for (int n : arr1) {
7 while (n > 0) {
8 us.insert(n);
9 n /= 10;
10 }
11 }
13 for (int n : arr2) {
14 while (n > 0) {
15 if (us.count(n)) {
16 res = max(res, (int)log10(n) + 1);
17 break;
18 }
19 n /= 10;
20 }
21 }
23 return res;
24 }
25 };