Skip to content

Commit 37c7fbf

Browse files
add skeleton for 1049
1 parent 703bc3d commit 37c7fbf

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 1049. Last Stone Weight II
5+
*
6+
* We have a collection of rocks, each rock has a positive integer weight.
7+
* Each turn, we choose any two rocks and smash them together.
8+
* Suppose the stones have weights x and y with x <= y. The result of this smash is:
9+
* If x == y, both stones are totally destroyed;
10+
* If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x.
11+
* At the end, there is at most 1 stone left. Return the smallest possible weight of this stone (the weight is 0 if there are no stones left.)
12+
*
13+
* Example 1:
14+
* Input: [2,7,4,1,8,1]
15+
* Output: 1
16+
*
17+
* Explanation:
18+
* We can combine 2 and 4 to get 2 so the array converts to [2,7,1,8,1] then,
19+
* we can combine 7 and 8 to get 1 so the array converts to [2,1,1,1] then,
20+
* we can combine 2 and 1 to get 1 so the array converts to [1,1,1] then,
21+
* we can combine 1 and 1 to get 0 so the array converts to [1] then that's the optimal value.
22+
*
23+
* Note:
24+
* 1 <= stones.length <= 30
25+
* 1 <= stones[i] <= 100
26+
* */
27+
public class _1049 {
28+
public static class Solution1 {
29+
public int lastStoneWeightII(int[] stones) {
30+
//TODO: implement it
31+
return 1;
32+
}
33+
}
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1049;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1049Test {
10+
private static _1049.Solution1 solution1;
11+
private static int[] stones;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1049.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
stones = new int[]{2, 7, 4, 1, 8, 1};
21+
assertEquals(1, solution1.lastStoneWeightII(stones));
22+
}
23+
24+
25+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy