# \#263 Ugly Number ## *給定一數,判斷其是否有不是2或3或5的質因數* ## Log - build 20210601 by syhuang ## 初見 - 用2/3/5去除,除到最後不是1就表示有2/3/5以外的質因數,注意edge case(負數無法質因數分解) ```javascript= var isUgly = function(n) { if(n<=0) return false; while(n%2==0) n/=2; while(n%3==0) n/=3; while(n%5==0) n/=5; return (n==1); }; ``` ## 備註 ## 參考 ###### tags: `leetcode`, `leetcode-easy`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up