Skip to content

Commit 9ad71d7

Browse files
author
王俊超
committed
commit
1 parent 6cecaff commit 9ad71d7

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

【258】【Add Digits】/src/Solution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ public int addDigits(int num) {
1111

1212
int result = 0;
1313

14-
while (num != 0) {
14+
while (num > 0) {
1515
result += num % 10;
1616
num /= 10;
1717

18+
// 需要重新进行位相加
1819
if (num == 0 && result > 9) {
1920
num = result;
2021
result = 0;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @author: wangjunchao(王俊超)
3+
* @time: 2018-10-10 13:35
4+
**/
5+
public class Test {
6+
public static void main(String[] args) {
7+
Solution solution = new Solution();
8+
9+
System.out.println(solution.addDigits(38));
10+
System.out.println(solution.addDigits(999999999));
11+
System.out.println(solution.addDigits(100000000));
12+
}
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @author: wangjunchao(王俊超)
3+
* @time: 2018-10-10 13:45
4+
**/
5+
public class Solution {
6+
public boolean isUgly(int num) {
7+
8+
if (num < 1) {
9+
return false;
10+
} else if (num == 1) {
11+
return true;
12+
}
13+
14+
int remainder;
15+
while ((num % 2) == 0) {
16+
num /= 2;
17+
}
18+
19+
while ((num % 3) == 0) {
20+
num /= 3;
21+
}
22+
23+
while ((num % 5) == 0) {
24+
num /= 5;
25+
}
26+
27+
return num == 1;
28+
}
29+
}

0 commit comments

Comments
 (0)