iT邦幫忙

0

自主學習30日-LeetCode 326:Power of Three

  • 分享至 

  • xImage
  •  

326.Power of Three

題目

給定一個整數 n,
判斷它是否是 3 的冪次方(即 3^x,其中 x 是整數)。

解題思路

1.若 n <= 0 → false

2.只要 n % 3 == 0 → 令 n /= 3

3.最後檢查 n == 1 是否成立

https://ithelp.ithome.com.tw/upload/images/20251020/20169298TFiP0efDZ5.pnghttps://ithelp.ithome.com.tw/upload/images/20251020/20169298Lp83Ov7sbD.png


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言