You are given an integer array nums containing positive integers. We define a function encrypt such that encrypt(x) replaces every digit in x with the largest digit in x. For example, encrypt(523) = 555 and encrypt(213) = 333.
classSolution { inthelper(int n){ int best = 0, cnt = 0; while(n) { best = max(best, n % 10); cnt += 1; n /= 10; } int res = 0; for(int i = 0; i < cnt; i++) { res += best; best *= 10; } return res; } public: intsumOfEncryptedInt(vector<int>& nums){ int res = 0; for(auto& n : nums) res += helper(n); return res; } };