Skip to content

Latest commit

 

History

History

1085

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

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

 

Example 1:

Input: nums = [34,23,1,24,75,33,54,8]
Output: 0
Explanation: The minimal element is 1, and the sum of those digits is 1 which is odd, so the answer is 0.

Example 2:

Input: nums = [99,77,33,66,55]
Output: 1
Explanation: The minimal element is 33, and the sum of those digits is 3 + 3 = 6 which is even, so the answer is 1.

 

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

Companies:
Amazon

Related Topics:
Array, Math

Similar Questions:

Solution 1.

// OJ: https://leetcode.com/problems/sum-of-digits-in-the-minimum-number/
// Author: github.com/lzl124631x
// Time: O(N)
// Space: O(1)
class Solution {
public:
    int sumOfDigits(vector<int>& A) {
        int n = *min_element(begin(A), end(A)), sum = 0;
        while (n) {
            sum += n;
            n /= 10;
        }
        return 1 - sum % 2;
    }
};