EasyNo. 1085LeetCode Premium
Sum of Digits in the Minimum Number — LeetCode 1085 Python Solution
- Pattern
- Math and Number Theory
- Topics
- Array, Math
- 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
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
- Time
- O(n) or O(1)
- Space · auxiliary
- O(1)
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
| No. | Problem | Difficulty |
|---|---|---|
| 1093 | Statistics from a Large Sample | Medium |
| 0048 | Rotate Image | Medium |
| 0066 | Plus One | Easy |
| 0189 | Rotate Array | Medium |
| 0204 | Count Primes | Medium |
| 0335 | Self Crossing | Hard |
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.