Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 263. Ugly Number

Posted on 2021-04-10 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
bool isUgly(int n) {
if (n <= 0) return false;
int factors[] = {2, 3, 5};
for (int factor : factors)
while (n % factor == 0)
n /= factor;
return n == 1;
}
};
# Math
LeetCode 154. Find Minimum in Rotated Sorted Array II
LeetCode 264. Ugly Number II
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%