Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
													Tags
													
											
												
												- 유루건
- 코테
- 건담헤드
- 게임
- 취미
- 눈알빠지겠네
- 우리시대의역설
- 가챠
- DIY
- LeetCode
- 30mf
- 누룽지소금빵
- 발더스게이트
- 제프딕슨
- 바질토마토뭐시기
- 맛집
- 발더스모드
- 메탈퍼즐
- javascript
- 지쿠악스
- 롱라이플
- 노노그램
- 코딩테스트
- 블라인드박스
- 프라모델
- 포켓몬
- 지리데칼
- 밥무하마드
- 미앤아이
- 건담
													Archives
													
											
												
												- Today
- Total
.Zzumbong
[leetCode/JS] 263. Ugly Number 본문
문제 설명
An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.
Given an integer n, return true if n is an ugly number.
입출력 예
Example 1:
Input: n = 6
Output: true
Explanation: 6 = 2 × 3
Example 2:
Input: n = 1
Output: true
Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
Example 3:
Input: n = 14
Output: false
Explanation: 14 is not ugly since it includes the prime factor 7.
Constraints
- -231 <= n <= 231 - 1
내 솔루션
- 뭐.. 2, 3, 5 로 나눠질떄까지 나누다가 n이 1이되어 while을 빠져나오면 true,
- 아니면 false인 상황이다.
var isUgly = function(n) {
  if(n <= 0) return false;
  while(n !== 1){
    if(n % 2 === 0){
      n /= 2;
    } else if(n % 3 === 0){
      n /= 3;
    } else if(n % 5 === 0){
      n /= 5;
    } else {
      return false;
    }
  }
  return true;
};감상평
- 왜 2, 3, 5로 나눠지는 이 숫자가 어글리 할까? 몰?루
'coding test > leetCode' 카테고리의 다른 글
| [leetCode/JS] 696. Count Binary Substrings (2) | 2022.11.23 | 
|---|---|
| [leetCode/JS] 1360. Number of Days Between Two Dates (0) | 2022.11.23 | 
| [leetCode/JS] 223. Rectangle Area (1) | 2022.11.23 | 
| [leetCode/JS] 1975. Maximum Matrix Sum (1) | 2022.11.23 | 
| [leetCode/JS] 374. Guess Number Higher or Lower (1) | 2022.11.23 | 
			  Comments