Skip to content

Commit 13b97e1

Browse files
add 1551
1 parent 2bcffee commit 13b97e1

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1551|[Minimum Operations to Make Array Equal](https://leetcode.com/problems/minimum-operations-to-make-array-equal/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1551.java) | |Medium|Math|
1112
|1550|[Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1550.java) | |Easy|Array|
1213
|1545|[Find Kth Bit in Nth Binary String](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1545.java) | |Medium|String|
1314
|1544|[Make The String Great](https://leetcode.com/problems/make-the-string-great/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1544.java) | |Easy|String, Stack|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1551 {
4+
public static class Solution1 {
5+
public int minOperations(int n) {
6+
int min = 1;
7+
int max = 2 * (n - 1) + 1;
8+
int finalNumber = (max + min) / 2;
9+
int[] arr = new int[n];
10+
for (int i = 0; i < n; i++) {
11+
arr[i] = 2 * i + 1;
12+
}
13+
int ops = 0;
14+
for (int i = 0; i < n / 2; i++) {
15+
ops += finalNumber - arr[i];
16+
}
17+
return ops;
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1551;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1551Test {
10+
private static _1551.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1551.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.minOperations(3));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)