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)


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