[LeetCode] Sum of Digits in the Minimum Number

1085. Sum of Digits in the Minimum Number

Given an integer array nums, return 0 if the sum of the digits of the minimum integer in nums is odd, or 1 otherwise.

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
int sumOfDigits(vector<int>& nums) {
int mi = *min_element(begin(nums), end(nums));
int res = 0;
while(mi) {
res += mi % 10;
mi /= 10;
}
return !(res & 1);
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2024/05/14/PS/LeetCode/sum-of-digits-in-the-minimum-number/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.