Sum of Digits in the Minimum Number — LeetCode 1085 Python Solution
EasyLeetCode PremiumArrayMath
- Problem
- #1085
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
The problem
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
- 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.
Python solution
Python
class Solution:
def sumOfDigits(self, nums: List[int]) -> int:
x = min(nums)
s = 0
while x:
s += x % 10
x //= 10
return s & 1 ^ 1Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) or O(1) |
| Space | O(1) auxiliary |
Pattern: Math and Number Theory
Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 1085. Sum of Digits in the Minimum Number is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math.
The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 1085. Sum of Digits in the Minimum Number?
- LeetCode 1085. Sum of Digits in the Minimum Number is rated Easy on LeetCode.
- What topics does LeetCode 1085. Sum of Digits in the Minimum Number cover?
- LeetCode 1085. Sum of Digits in the Minimum Number is tagged Array and Math on LeetCode.
- Is LeetCode 1085. Sum of Digits in the Minimum Number a premium problem?
- Yes. LeetCode 1085. Sum of Digits in the Minimum Number is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.