Skip to content

Commit 17c9773

Browse files
refactor 397
1 parent 36cd635 commit 17c9773

File tree

1 file changed

+1
-32
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+1
-32
lines changed

src/main/java/com/fishercoder/solutions/_397.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,14 @@
66
import java.util.Queue;
77
import java.util.Set;
88

9-
/**
10-
* 397. Integer Replacement
11-
*
12-
* Given a positive integer n and you can do operations as follow:
13-
14-
If n is even, replace n with n/2.
15-
If n is odd, you can replace n with either n + 1 or n - 1.
16-
What is the minimum number of replacements needed for n to become 1?
17-
18-
Example 1:
19-
20-
Input:
21-
8
22-
23-
Output:
24-
3
25-
26-
Explanation:
27-
8 -> 4 -> 2 -> 1
28-
Example 2:
29-
30-
Input:
31-
7
32-
33-
Output:
34-
4
35-
36-
Explanation:
37-
7 -> 8 -> 4 -> 2 -> 1
38-
or
39-
7 -> 6 -> 3 -> 2 -> 1*/
409
public class _397 {
4110

4211
public static class Solution1 {
4312
public int integerReplacement(int n) {
4413
long min = Long.MAX_VALUE;
4514
Set<long[]> set = new HashSet();
4615
Queue<long[]> q = new LinkedList();
47-
long[] pair = new long[] {n, 0};
16+
long[] pair = new long[]{n, 0};
4817
q.offer(pair);
4918
while (!q.isEmpty()) {
5019
int size = q.size();

0 commit comments

Comments
 (0)