Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
404 B
2
Indexable
Never
class Solution {
    int ask(int x)
    {
        if(x<10)return x;
        return max(x%10,ask(x/10));
    }
public:
    int maxSum(vector<int>& nums) {
        int n=nums.size(),i,j,ans=-1;
        for(i=0;i<n;i++)for(j=i+1;j<n;j++)if(ask(nums[i])==ask(nums[j]))ans=max(ans,nums[i]+nums[j]);
        return ans;
    }
};

ok os this code in c++ is optimized or not compared to above codes