LeetCode 1085. Sum of Digits in the Minimum Number

Description

https://leetcode.com/problems/sum-of-digits-in-the-minimum-number/

Given an array A of positive integers, let S be the sum of the digits of the minimal element of A.

Return 0 if S is odd, otherwise return 1.

Example 1:

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

Example 2:

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

Constraints:

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

Explanation

check two strings if counts of vowels are the same.

Python Solution

class Solution:
    def sumOfDigits(self, A: List[int]) -> int:
        min_num = min(A)
        
        digit_sum = 0
        for c in str(min_num):
            digit_sum += int(c)
            
        return 1 if digit_sum % 2 == 0 else 0 
            
  • Time Complexity: O(N)
  • Space Complexity: O(1)

Leave a Reply

Your email address will not be published.