- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution754.java
More file actions
Latest commit
executable file
·33 lines (28 loc) · 737 Bytes
/
Copy pathSolution754.java
File metadata and controls
executable file
·33 lines (28 loc) · 737 Bytes
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
32
/**
* Created by slade on 2019/7/12.
*/
publicclassSolution754 {
inttmp = 1;
intsum = 0;
publicintreachNumber(inttarget) {
target = Math.abs(target);
while (true) {
sum += tmp;
if (target == sum) returntmp;
if (sum > target) {
if ((sum - target) % 2 == 0) {
returntmp;
} elseif (tmp % 2 == 1) {
returntmp + 2;
} else {
returntmp + 1;
}
}
tmp += 1;
}
}
publicstaticvoidmain(String[] args) {
Solution754s = newSolution754();
System.out.println(s.reachNumber(4));
}
}