#1780
Check if Number is a Sum of Powers of Three
pupil · 445 · lc medium +26 · verified · 79.4% accepted · 1,669 likes · top 91%
Description
Given an integer n, return true if n can be represented as a sum of distinct powers of three, and false otherwise.
Example 1:
Input: n = 12
Output: true
Explanation: 12 = 31 + 32
Example 2:
Input: n = 91
Output: true
Explanation: 91 = 30 + 32 + 34
Example 3:
Input: n = 21
Output: false
Code
1
2
3