forked from sowon-dev/AlgorithmStudy_Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIceCreamParlor.java
More file actions
28 lines (23 loc) ยท 858 Bytes
/
IceCreamParlor.java
File metadata and controls
28 lines (23 loc) ยท 858 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;
import java.util.Arrays;
public class IceCreamParlor {
static int[] icecreamParlor(int m, int[] arr) {
// ์์ด์คํฌ๋ฆ ๋ง์ข
๋ฅ ๋ฐฐ์ด์ธ arr์์ ๊ฐ์ง๊ณ ์๋ ๋ m์ผ๋ก ๋๊ฐ์ง ๋ง์ ์ฌ๋ ค๋ฉด ๋ช๋ฒ์งธ ๋ง์ ๊ณจ๋ผ์ผํ๋ ์ง๋ฅผ ๋ฆฌํดํ๋ ๋ฌธ์ ์ด๋ค.
int[] result = new int[2];
for (int i = 0; i < arr.length; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (m == (arr[i] + arr[j])) {
result[0] = i + 1;
result[1] = j + 1;
break;
}
}
}
System.out.println(Arrays.toString(result));
return result;
}
public static void main(String[] args) {
System.out.println(icecreamParlor(4, new int[] {1, 4, 5, 3, 2}) + ", ans: [1 4]");
System.out.println(icecreamParlor(4, new int[] {2, 2, 4, 3}) + ", ans: [1 2]");
}
}