Leetcode - Power of Three (Python)

preview_player
Показать описание
April 2021 Leetcode Challenge
Leetcode - Power of Three #326
Difficulty: Easy
Рекомендации по теме
Комментарии
Автор

divisible is not enough.. if the quotient is 2 or 5 for example, then it is not going to work

karthikkumaresan
Автор

don't know if you have notifs or not on but here's how the last code you showed works

since the max is 32 bit integer limit (2^31 -1 / 2147483647), they found the highest possible value were 3^x < 2^31 -1 (3^x because we're finding powers of 3)

in this case, it's 19.

since no number can be higher than that, you can check if the number is a power of 3 when 3^19 % 3 = 0 (no remainder)

therefore, it returns true if n will have no remainder

and false if it does have one

siwence
Автор

You're amazing mate! Thank you so much!

ishan