題目連結:https://leetcode.cn/problems/minimum-element-after-replacement-with-digit-sum/
題解程式碼:
class Solution {
public:
int minElement(vector<int>& nums) {
vector<int> n;
for(int i = 0;i < nums.size();i ++)
{
int x = nums[i];
int cnt = 0;
while(x)
{
cnt += x % 10;
x /= 10;
}
n.push_back(cnt);
}
sort(n.begin(),n.end());
return n[0];
}
};