-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTowerBreakers.java
More file actions
28 lines (23 loc) Β· 847 Bytes
/
TowerBreakers.java
File metadata and controls
28 lines (23 loc) Β· 847 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
package hackerrank;
public class TowerBreakers {
static int towerBreakers(int n, int m) {
// μλ κ²μκ·μΉμ μ μ©νμ¬ μ²«λ²μ§Έ νλ μ΄μ΄κ° μΉμλ©΄ 1μ, λλ²μ§Έ νλ μ΄μ΄κ° μΉμλ©΄ 2λ₯Ό 리ν΄νλ λ¬Έμ
// nκ°μ νμκ° μκ³ κ° νμμ λμ΄λ mμ΄λ€.
// λμκ°λ©΄μ κ²μμ μ§ννλ©°, νλ μ΄μ΄λ λμ΄xμ νμλ₯Ό μ ννμ¬ κΈΈμ΄ yλ§νΌμ μ κ±°ν μ μλ€.
// μ΄λ 1 <= y < xμ΄κ³ x%y = 0μ΄λ€.
//νμκ°
if (m == 1) {
return 2;
}
if (n % 2 == 0) {
return 2;
} else {
return 1;
}
}
public static void main(String[] args) {
System.out.println(towerBreakers(2, 6) + ". ans: 2");
System.out.println(towerBreakers(2, 2) + ". ans: 2");
System.out.println(towerBreakers(1, 4) + ". ans: 1");
}
}