Skip to content

Commit 3437ece

Browse files
authored
Create minimum-element-after-replacement-with-digit-sum.cpp
1 parent 5535f72 commit 3437ece

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Time: O(nlogr)
2+
// Space: O(1)
3+
4+
// array
5+
class Solution {
6+
public:
7+
int minElement(vector<int>& nums) {
8+
const auto& f = [](int x) {
9+
int result = 0;
10+
for (; x ; x /= 10) {
11+
result += x % 10;
12+
}
13+
return result;
14+
};
15+
16+
int result = numeric_limits<int>::max();
17+
for (const auto& x : nums) {
18+
result = min(result, f(x));
19+
}
20+
return result;
21+
}
22+
};

0 commit comments

Comments
 (0)