Skip to content

Commit d41b348

Browse files
committed
issue #29 towerBreakers java
1 parent caf847c commit d41b348

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

β€Žsrc/hackerrank/GameofStones.javaβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,5 @@ public static void main(String[] args) {
2323
System.out.println(gameOfStones(10)+", ans: First"); //1.428...
2424
System.out.println(gameOfStones(13)+", ans: First"); //1.857...
2525
System.out.println(gameOfStones(14)+", ans: Second"); //2
26-
27-
2826
}
2927
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package hackerrank;
2+
3+
public class TowerBreakers {
4+
5+
static int towerBreakers(int n, int m) {
6+
// μ•„λž˜ κ²Œμž„κ·œμΉ™μ„ μ μš©ν•˜μ—¬ 첫번째 ν”Œλ ˆμ΄μ–΄κ°€ 승자면 1을, λ‘λ²ˆμ§Έ ν”Œλ ˆμ΄μ–΄κ°€ 승자면 2λ₯Ό λ¦¬ν„΄ν•˜λŠ” 문제
7+
// n개의 νƒ€μ›Œκ°€ 있고 각 νƒ€μ›Œμ˜ λ†’μ΄λŠ” m이닀.
8+
// λŒμ•„κ°€λ©΄μ„œ κ²Œμž„μ„ μ§„ν–‰ν•˜λ©°, ν”Œλ ˆμ΄μ–΄λŠ” 높이x의 νƒ€μ›Œλ₯Ό μ„ νƒν•˜μ—¬ 길이 yλ§ŒνΌμ„ μ œκ±°ν•  수 μžˆλ‹€.
9+
// μ΄λ•Œ 1 <= y < x이고 x%y = 0이닀.
10+
11+
//νƒ€μ›Œκ°€
12+
if (m == 1) {
13+
return 2;
14+
}
15+
16+
if (n % 2 == 0) {
17+
return 2;
18+
} else {
19+
return 1;
20+
}
21+
}
22+
23+
public static void main(String[] args) {
24+
System.out.println(towerBreakers(2, 6) + ". ans: 2");
25+
System.out.println(towerBreakers(2, 2) + ". ans: 2");
26+
System.out.println(towerBreakers(1, 4) + ". ans: 1");
27+
}
28+
}

0 commit comments

Comments
Β (0)