728x90
https://leetcode.com/problems/harshad-number
class Solution:
def sumOfTheDigitsOfHarshadNumber(self, x: int) -> int:
sum_of_digits = sum([int(i) for i in str(x)])
if x % sum_of_digits == 0:
return sum_of_digits
else:
return -1
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 205. Isomorphic Strings (0) | 2024.04.02 |
---|---|
[Leetcode] 58. Length of Last Word (1) | 2024.04.01 |
[Leetcode] 2962. Count Subarrays Where Max Element Appears at Least K Times (0) | 2024.03.29 |
[Leetcode] 41. First Missing Positive (1) | 2024.03.26 |
[Leetcode] 442. Find All Duplicates in an Array (0) | 2024.03.25 |