File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ LeetCode
22
22
|414|[ Third Maximum Number] ( https://leetcode-cn.com/problems/third-maximum-number/ ) | [ Java] ( https://github.com/xiao2shiqi/leetcode/blob/master/src/main/java/Solution414.java ) | Easy
23
23
|283|[ Move Zeroes] ( https://leetcode-cn.com/problems/move-zeroes/ ) | [ Java] ( https://github.com/xiao2shiqi/leetcode/blob/master/src/main/java/Solution283.java ) , [ Ruby] ( https://github.com/xiao2shiqi/leetcode/blob/master/ruby/solution283.rb ) | Easy
24
24
|268|[ Missing Number] ( https://leetcode-cn.com/problems/missing-number/ ) | [ Java] ( https://github.com/xiao2shiqi/leetcode/blob/master/src/main/java/Solution268.java ) , [ Ruby] ( https://github.com/xiao2shiqi/leetcode/blob/master/ruby/solution268.rb ) | Easy
25
- |263|[ Ugly Number] ( https://leetcode-cn.com/problems/ugly-number/ ) | [ Go] ( https://github.com/xiao2shiqi/leetcode/blob/master/go/263-solution.go ) | Easy
25
+ |263|[ Ugly Number] ( https://leetcode-cn.com/problems/ugly-number/ ) | [ Java ] ( https://github.com/xiao2shiqi/leetcode/blob/master/src/main/java/Solution263.java ) , [ Go] ( https://github.com/xiao2shiqi/leetcode/blob/master/go/263-solution.go ) | Easy
26
26
|237|[ Delete Node in a Linked List] ( https://leetcode-cn.com/problems/delete-node-in-a-linked-list/ ) | [ Java] ( https://github.com/xiao2shiqi/leetcode/blob/master/src/main/java/Solution237.java ) , [ Ruby] ( https://github.com/xiao2shiqi/leetcode/blob/master/ruby/solution237.rb ) | Easy
27
27
|232|[ Implement Queue using Stacks] ( https://leetcode-cn.com/problems/implement-queue-using-stacks/ ) | [ Java] ( https://github.com/xiao2shiqi/leetcode/blob/master/src/main/java/Solution232.java ) | Easy
28
28
|228|[ Summary Ranges] ( https://leetcode-cn.com/problems/summary-ranges/ ) | [ Java] ( https://github.com/xiao2shiqi/leetcode/blob/master/src/main/java/Solution228.java ) | Easy
Original file line number Diff line number Diff line change
1
+ /**
2
+ * LC#263: Ugly Number
3
+ * Link:https://leetcode-cn.com/problems/ugly-number/
4
+ * 思路:对 n 反复除以 2,3,5 直到 n 不再包含质数,剩下的数为1,则是丑数
5
+ *
6
+ * @author Phoenix on 2021/5/9.
7
+ */
8
+ public class Solution263 {
9
+
10
+ private static boolean isUgly (int n ) {
11
+ if (n <= 0 ) {
12
+ return false ;
13
+ }
14
+ int [] factors = {2 , 3 , 5 };
15
+ for (int factor : factors ) {
16
+ while (n % factor == 0 ) {
17
+ n /= factor ;
18
+ }
19
+ }
20
+ return n == 1 ;
21
+ }
22
+
23
+ public static void main (String [] args ) {
24
+ int n = 6 ;
25
+ boolean res = isUgly (n );
26
+ System .out .println (res );
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments